google / VoltAir

http://google.github.io/VoltAir
Apache License 2.0
317 stars 85 forks source link

Level coordinates #7

Closed vsidou closed 9 years ago

vsidou commented 9 years ago

Hi,

I've been digging in VolAir code and trying to understand the coordinated defined in the levels. As i read in the FAQ it seems the level editor is and will not be released which is understandable. My question is with the Multiplayer level. I choosed it because it fill the camera.

I simplified the level with the simple background here :

Level {
    cameraBoundary: Qt.rect(0.21014, -24.2574, 20.7089, 11.6926)
    completionThreshold: 25
    fileName: "arena2"
    fillCamera: true
    parallaxOrigin.x: 11.220729
    parallaxOrigin.y: -19.160648
    Polygon {
        body.active: false
        body.vertices: [[-12.1123, 12.0156], [12.1731, 12.0156], [12.1731, -1.70233], [-12.1123, -1.70233]] 
        objectName: "actor39986"
        property alias image: graphic0
        x: 10.592566
        y: -23.612015
        z: -10
        ImageRenderer {
            cacheRenderParams: actor39986.body.bodyType === Body.StaticBody
            id: graphic0
            sizeScale: 23.742374
            source: Util.getPathToImage("background_mp/bg_mp1_flat.jpg")
        }
    }

}

From the Box2D documentation when positionning a Body (Polygon here) we always define its center. From the source code CameraBoundary is also defined as world coordinates. Even armed with that i cannot understand how Polygon ( x: 10.59256, y: -23.612015) is on the center.

Could someone maybe explain this process slowly and nicely for me please ? :)

Thank you

adderly commented 9 years ago

Well, It is actually by chance you got it there (in the center). :dart: The scaling in your graphic made it easier for confusing you.

If you want turn on the debugDraw which is in the UI.qml in the element PlayerHUD there is a debugDraw. Maybe Using a simpler object you could find out. Change the positions where ever you find good to see that, try this one:

 Actor{
        id:actorShowOff
        x: 10.592566
        y: -23.612015
        CircleBody{
            active: true
            radius: 0.5
        }
        ImageRenderer {
            cacheRenderParams: actor39986.body.bodyType === Body.StaticBody
            id: graphic2
//            sizeScale: 23.742374
            source: Util.getPathToImage("background_mp/bg_mp1_flat.jpg")
        }
    }

Feel free to ask any questions.

vsidou commented 9 years ago

Hi,

Based on the cameraBoundary : Qt.rect(0.21014, -24.2574, 20.7089, 11.6926) I get the rect.center() ==> QPointF(10.5646, -18.4111) I defined these values as the X/Y of the Actor you gave as an example. And it truly set the object on the center :) thanks.

But i wonder for the previous Actor (Polygon actor) which display a background image on the Level, i commented the sizeScale. The object get displayed on the center of X but near the top for Y. This is understandable as Y = -23.612015 which is not the center of camera boundary. I also noticed that the "active" property is set to false. So in Body::updateBeforePhysics() it doesn't call mBody->SetTransform(...) for non active Actor. This means the "Y" position for this kind of "Background" actor need to be quite specific based on the sizeScale of ImageRenderer. Could you maybe explain how this "Y" is chosen for the "Background" actor please ?

Thanks you

adderly commented 9 years ago

Well as far as i know that is the default behavior in the ImageRenderer which is not so usefull. I did a little modification for this in the ImageRenderer. You can set a custom localBox to the image renderer and it does a better thing.

https://gist.github.com/adderly/48e570ba900765d5ce60

With that you could do something like:

 Actor{
        id:actorShowOff
        x: 10.592566
        y: -23.612015
        CircleBody{
            active: false
            radius: 0.5
        }
        ImageRenderer {
            customLocalBox: Qt.rect(0.21014, -10.2574, 10.7089, 11.6926)
            cacheRenderParams: actor39986.body.bodyType === Body.StaticBody
            id: graphic2
//            sizeScale: 23.742374
            source: Util.getPathToImage("background_mp/bg_mp1_flat.jpg")
        }
    }

If you want push these changes up, i got a mess in my repo. Not gonna clean that for now. :)

vsidou commented 9 years ago

Hey there,

thanks i got it now. Thanks also for the update. Actually i'm learning Box2D/Liquidfun from VoltAir code. This is great starting tutorial. I hope to make one quality game like that in the near futur :)

Thanks again

vsidou commented 9 years ago

Hello

one more question though before closing this topic. I was trying to understand the ParticleLayer principles on the game. So far i understand that this is were specificaly Liquidfun is being really used.

Now armed with that i manage to understand the logic behind Particles, ParticleEmitters ... But one thing is bothering me. In the multiplayer level arena.qml i can see this :

    ParticleLayer {
        id: particleLayer0
        radius: 0.075
    }
    ParticleLayer {
        id: particleLayer1
    }
    ParticleLayer {
        id: particleLayer2
    }
    ParticleLayer {
        id: particleLayer3
    }

but only particleLayer0 seems to be used. I don't really see where layers 1 to 3 are being used. Could you point me on the right direction for this please ?

THanks

adderly commented 9 years ago

I don't know what they are doing there. Try deleting them and if it runs normaly then you're good to go.

vsidou commented 9 years ago

Yeah

Strange they seem not to be needed. Maybe they were added using the level editor... Thanks for the answer