【问题标题】:AndEngine - how to know the position for placing an object on a sceneAndEngine - 如何知道在场景中放置对象的位置
【发布时间】:2013-10-31 17:09:46
【问题描述】:

我目前正在使用 AndEngine GLES2 Center 设置场景,我有以下疑问: 我放置了一个背景,据我了解,在这个新版本的 AndEngine 中,精灵的位置应该相对于左下角。

但是如果我想将一个对象放置在位置 (x,y) 并且我在 FireWorks 等编辑器中看到这样的位置并在 Sprite 参数中使用它,它将不会出现在与出现在编辑器中相同的位置。如何知道放置物体的正确位置?

谢谢!

【问题讨论】:

  • 你是对的,锚中心使用左下角的坐标,但我猜 FireWorks 中的位置与手机分辨率有点偏差。所以可能想在 FireWorks 和引擎上检查画布大小
  • 但是您对如何将对象定位在特定位置有任何建议吗?怎么猜那个位置?做不同的测试?
  • 我使用原始的 GLES2 分支,对于定位,我会说从 0,0 开始并进行更改,直到您到达您想要的位置,然后您可以使用以前的坐标作为参考点。我在代码中的定位从未使用过像 FireWorks 这样的其他编辑器。

标签: android sprite andengine andengine-gles-2


【解决方案1】:

每个 Sprite(实际上是实体)都有一个锚点。当您将 Sprite 放置在 Scene 位置 (x, y) 上时,这意味着您将 Sprite 的锚点固定在坐标 (x, y) 上。

在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.

注意:当实体旋转、倾斜和缩放时,也会使用锚点。所以,在 GLES2 分支中,当实体在旋转时,人们常常认为实体也在移动,其实不然,锚点总是固定在坐标 (x, y) 上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多