android - 物理 body 不遵循路径修改器

标签 android andengine

我有一个有 body 的 Sprite 。我想通过路径移动 Sprite 。我已经尝试使用 PathModifier 执行此操作, Sprite 会按原样移动,但它的 body 不会跟随 Sprite 的位置。

我可以将 Sprite 和 body 一起移动吗?我真的必须计算路径的速度并将其应用于主体对象,因为这看起来很难吗?

Sprite 是这样初始化的

  ...
  this.sprite = new Sprite(this.x, this.y, textureRegion);
  this.rectangleBody = PhysicsFactory.createBoxBody(
        physicsWorld,
        this.sprite,
        BodyDef.BodyType.StaticBody,
        this.fixtureDef);
  pPhysicsConnector = new PhysicsConnector(this.sprite, rectangleBody, true, false);
  physicsWorld.registerPhysicsConnector(pPhysicsConnector);
  scene.attachChild(this.sprite);

然后用这段代码移动

     Shape shape = entity.getShape();
     Float[] reverseXPath = ArrayUtils.clone(xPath.toArray(new Float[xPath.size()]));
     ArrayUtils.reverse(reverseXPath);
     Float[] reverseYPath = ArrayUtils.clone(yPath.toArray(new Float[yPath.size()]));
     ArrayUtils.reverse(reverseYPath);
     SequenceEntityModifier oneSequence = new SequenceEntityModifier(
           new PathModifier(
                 duration,
                 new PathModifier.Path(
                       ArrayUtils.toPrimitive(xPath.toArray(new Float[xPath.size()])),
                       ArrayUtils.toPrimitive(yPath.toArray(new Float[yPath.size()]))),
                 IEaseFunction.DEFAULT),
           new PathModifier(
                 duration,
                 new PathModifier.Path(
                       ArrayUtils.toPrimitive(reverseXPath),
                       ArrayUtils.toPrimitive(reverseYPath)),
                 IEaseFunction.DEFAULT));
     shape.registerEntityModifier(new LoopEntityModifier(oneSequence));

最佳答案

我想你会发现这篇文章很有用

http://www.andengine.org/forums/post28936.html

关于android - 物理 body 不遵循路径修改器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9711259/

相关文章:

java - For 语句不适用于每个数组元素?

java - 在 Android 上使用 andengine 在 ButtonSprite 上添加 OnClickListener

android - 加速度计在所有设备上都无法正常工作

android - 我如何从andengine中的Sprite获取像素的颜色/alpha?

java - 使用 SDL 将现有的 Lunar Lander 程序从 C 转换到 Android 手机

android - 当 Android 应用程序从 Play 商店更新时,如果有一个正在运行的实例,它会退出吗?

安卓工作室 : Fail to parse SDK may be missing the directory add-ons

android - 如何减慢按下按钮时 Android GridView 的滚动速度? (往后靠)

android - 如何在travis-ci上显示android模拟器的logcat?

android - 在 Chrome beta 浏览器而不是默认浏览器中运行 Android 4.0 上的 Selenium 测试