Coordinate conversion
Coordinate conversion can be very useful in situations where a Scene
object relies on a number of entities to act as base layers for a game's sprites. It's not uncommon for games which contain many parents, each with their own set of children, to need to obtain a child's position relative to the Scene
object at one point or another. This isn't a problem in situations where each of the layers remain at the same (0, 0) coordinates on the scene throughout the entire game. On the other hand, when our layers start to move around, child positions will move with the parent but their coordinates on the layer will remain the same. This topic is going to cover converting scene coordinates to local coordinates in order to allow nested entities to be properly positioned on the scene.
How to do it…
Import the following code to the onCreateScene()
method of any BaseGameActivity
of your choice.
The first step in this recipe is to create and apply a
Rectangle
object to theScene
object...