How to get the world coordinates of a point in a child actor?

三世轮回 提交于 2019-12-10 07:01:03

问题


I have Group objects that consist of other Group objects, that finally consist of Actor objects. Now, when the groups and actors are rotated, offset and scaled, the coordinates in the "world", or in relation to the root node change. How do I get the world coordinates of a point in an actor's local space?

To illustrate a bit more, here's an example of what I want:

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.

回答1:


You can either use Actor.localToParentCoordinates() if you want to go just one step higher in your hierarchy of Groups and Actors, or directly use Actor.localToStageCoordinates() to get the "stage-global" coordinates directly. In this case, libGDX will recursively apply the localToParentCoordinates until it hits the root element of your stage.



来源:https://stackoverflow.com/questions/23699481/how-to-get-the-world-coordinates-of-a-point-in-a-child-actor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!