如何获取子演员中某个点的世界坐标? [英] How to get the world coordinates of a point in a child actor?

查看:12
本文介绍了如何获取子演员中某个点的世界坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

你可以使用 Actor.localToParentCoordinates()GroupsActors 的层次结构中更高,或直接使用 Actor.localToStageCoordinates() 获取舞台全局"直接坐标.在这种情况下,libGDX 将递归地应用 localToParentCoordinates 直到它到达舞台的根元素.

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.

这篇关于如何获取子演员中某个点的世界坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆