Hi! I’m new to defold and I’m trying to make a retro game to test the engine.
I made a 160x160 room with a bouncing ball inside, using simple code instead of the physics engine. Every frame I move the ball according to my Xspeed and Yspeed variables, reverting the speed if the ball when it hits a wall or the ground.
The room BG, the ball and it’s code are inside the same collection, which I scaled to 3x and placed centered into my 720x480 main collection.
I expected the coordinates to be relative to the room collection, but when I use get_position for the ball I get the screen coordinates, insted of the room-relative coordinates.
I wonder, Is there any method to get the position of a game object, relative to its parent? Thanks and sorry for my english.
Collections do not exist in runtime. You need to make something the child of another game object to get relative position. Either do that in the editor in the collection (drag the GO to its parent) or do it in runtime with “set_parent”. See http://www.defold.com/ref/go/#set_parent
Thanks! I was under the impression that a collection was a kind of object. So, just to be clear: Only Game Objects can be parents of Game Objects, and a child’s position is indeed relative to it’s parent, right? I’m having a hard time trying to understand Defold, coming from Actionscript and HaXe/OpenFL, that’s why I don’t really get what a collection is, and what can I do with it.