【问题标题】:Get position of a child according to the screen, not according to the parent, in AndEngine在AndEngine中根据屏幕而不是根据父母获取孩子的位置
【发布时间】:2014-04-18 04:51:05
【问题描述】:

我正在开发 AndEngine GLES2
我在场景中有一个实体,它在不同的位置附有近 24 个孩子(精灵)。我制作了一个函数,将实体从一个位置移动到另一个位置。每当我尝试获取孩子的位置时,它都会返回相同的结果位置,因为它根据父(实体)返回位置。正如您在下面的示例中看到的那样。

Entity myEntity = new Entity();
for(int i = 0; i < arraylist.size();i++)
{
    myEntity.attachChild(arraylist.get(i));
}
Log.i("MyLog","Y Position of one child "+arraylist.get(4).getY());//Assume it 231
Log.i("MyLog","Y Position of Entity "+myEntity.getY());//Assume it 0
myEntity.setPosition(0,200);
Log.i("MyLog","Y Position of one child "+arraylist.get(4).getY());//it will return 231

它将返回与开始时相同的位置。我想根据屏幕得到这个孩子的位置。我希望它现在是 431,因为它在屏幕上向下移动了 200 像素。

【问题讨论】:

    标签: entity andengine sprite


    【解决方案1】:

    为此,您应该使用convertLocalToSceneCoordinates(final float pX, final float pY) 函数,例如: myEntity.convertLocalToSceneCoordinates(arrayList.get(4).getX(),arrayList.get(4).getY()) 将根据实体所连接的场景返回一个具有 x 和 y 位置的浮点数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 2014-11-03
      • 1970-01-01
      相关资源
      最近更新 更多