简体   繁体   English

AndEngine-如何知道将对象放置在场景中的位置

[英]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. 我目前正在使用AndEngine GLES2 Center设置场景,我有以下疑问:我放置了背景,据我了解,使用新版本的AndEngine,精灵的位置应相对于左下角。

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. 但是,如果我想将对象放置在位置(x,y),并且在FireWorks之类的编辑器中看到该位置,并在Sprite参数中使用usit,则该对象将不会出现在与编辑器相同的位置。 How to know the correct position to place the object? 如何知道放置物体的正确位置?

thanks! 谢谢!

Every Sprite (actually Entity) has an anchor point. 每个Sprite(实际上是Entity)都有一个锚点。 When you place a Sprite on Scene position (x, y), it means you stick the anchor point of Sprite on the coordinates (x, y). 将Sprite放置在场景位置(x,y)上时,意味着将Sprite的锚点粘贴在坐标(x,y)上。

In AndEngine GLES2 and GLES2-AC branches, both anchor point and coordinates system are different. 在AndEngine GLES2和GLES2-AC分支中,锚点和坐标系都不同。

             |  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). 因此,在GLES2分支中,当实体旋转时,人们通常认为实体也在移动,但并非如此,锚点始终固定在坐标(x,y)上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM