【问题标题】:How to get the world coordinates of a point in a child actor?如何获取子演员中某个点的世界坐标?
【发布时间】:2014-07-05 03:42:41
【问题描述】:

我有 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.

【问题讨论】:

  • Actor.localToParentCoordinates()Actor.localToStageCoordinates()
  • @noone 谢谢!介意将此作为答案发布,以便我接受吗?

标签: libgdx coordinates scene2d


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-13
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 2020-09-12
    • 2019-08-22
    • 1970-01-01
    相关资源
    最近更新 更多