androidspriteandengineandengine-gles-2

AndEngine - how to know the position for placing an object on a scene


I am currently setting up a scene using AndEngine GLES2 Center and I have the following doubt: I placed a background and from what I understood, with this new version of AndEngine, the position of a sprite should be relative to the bottom-left.

But if I want to place an object in position (x,y) and I see such position in an editor like FireWorks and usit in the Sprite argument, it will not appear in the same place as appearing in the editor. How to know the correct position to place the object?

thanks!


Solution

  • Every Sprite (actually Entity) has an anchor point. When you place a Sprite on Scene position (x, y), it means you stick the anchor point of Sprite on the coordinates (x, y).

    In AndEngine GLES2 and GLES2-AC branches, both anchor point and coordinates system are different.

                 |  GLES2                    |  GLES2-AnchorCenter
    -------------+---------------------------+-------------------------------------
    anchor point | At corner of entity.      | As branch name, at center of entity.
                 | (left-top corner)         | (vertically and horizontally)
                 |                           |
                 |   anchor point            |
                 |   |                       |
                 |   V                       |      +-------------+
                 |   X-------------+         |      |             |
                 |   |             |         |      |      X <-------- anchor point
                 |   | I am Entity |         |      | I am Entity |
                 |   |             |         |      +-------------+
                 |   +-------------+         |
                 |                           |
    -------------+---------------------------+-------------------------------------
    coordinates  | Origin at left-top.       | Origin at left-bottom
                 | move right -> x increase, | move right -> x increase,
                 | move up -> y decrease.    | move up -> y increase.
    

    Note: The anchor point is also used when Entity rotates, skews and scales. So, in GLES2 branch, when entity is rotating, people often think the entity is also moving, but it doesn't, the anchor point is always fixed at coordinates (x, y).