4

我有Group由其他Group对象组成的对象,最终由Actor对象组成。现在,当组和演员被旋转、偏移和缩放时,“世界”中的坐标或相对于根节点的坐标会发生变化。如何获取演员本地空间中某个点的世界坐标?

为了说明更多,这是我想要的一个例子:

Group parentGroup;
Actor childInGroup;
...
parentGroup.addActor(childInGroup);
childInGroup.setPosition(10f, 15f);
childInGroup.setRotation(45f);

// Get the childInGroup's position in the world
float childWorldPosX = ...; // This is what I want to know
float childWorldPosY = ...; // ... and this.
4

1 回答 1

5

Actor.localToParentCoordinates()如果您想在Groupsand的层次结构中更上一层,您可以使用Actors,或者直接使用直接Actor.localToStageCoordinates()获取“舞台全局”坐标。在这种情况下,libGDX 将递归地应用localToParentCoordinates直到它到达你的阶段的根元素。

于 2014-05-16T17:17:13.020 回答