gpt4 book ai didi

java - Libgdx Actor.setBounds() 相对于 Actor.x 和 Actor.y 等

转载 作者:行者123 更新时间:2023-12-01 11:35:11 26 4
gpt4 key购买 nike

我在设置边界矩形位置时遇到麻烦,这就是我问这个的原因。当我设置 Actor 类型的对象的边界矩形位置时,看来我传递给 [setBounds(x,y,with,height)] 2 的坐标相对于 Actor 的 x 和 y目的。这是真的吗?

而且,当我使用 Group.addAction(Actions.MoveTo(x,y,duration)) 时,似乎 Actor对象不更新它的 x 和 y。这也是真的吗?如果是,我该如何更新?我不知道要覆盖什么。

最佳答案

否,设置边界会更新 Actor 的 x 和 y。

每个 Actor 的 x 和 y 可以被认为是他们本地的 x 和 y,但他们在屏幕上的实际位置是他们的 x 和 y 以及每个祖先(拥有 Group)的 x 和 y 的总和>).

当你移动一个Group(它本身就是一个Actor)时,你正在移动它的x和y。这不会修改其子级的 x 和 y,但它们在屏幕上的位置会因为上述原因而发生变化。

因此,如果您想将 Actor 移动到屏幕上的特定位置而不移动其任何祖先,则应该只更改其本地 x 和 y。因此,您需要从目标世界(又名舞台)位置中减去其所有祖先的 x 和 y 的总和。

static final Vector2 TEMP = new Vector2(); //reusable to avoid GC

...

TEMP.set(targetX, targetY); //world(aka stage) coordinates of target position
myActor.stageToLocalCoordinates(TEMP); //subtract ancestor positions to get local target position
myActor.addAction(Actions.moveTo(TEMP.x, TEMP.y, duration));

关于java - Libgdx Actor.setBounds() 相对于 Actor.x 和 Actor.y 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30074226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com