我在andengine中做了一个赛车游戏.MoveModifier()使汽车行驶。汽车同时是dynamicBody,但是汽车在行驶时却失去了dynamicBody特性。


  (enemy1 =汽车)


Sprite enemy1=new Sprite(0,0,this.enemyRegion1);
         enemy1.registerEntityModifier(
                    (IEntityModifier) new SequenceEntityModifier (
                            new MoveModifier(10, enemy1.getX(),  enemy1.getX()+400,
                                    enemy1.getY(), enemy1.getY())));
        final Vector2 velocity = Vector2Pool.obtain(5, 5);

        final FixtureDef enemyFixtureDef1 = PhysicsFactory.createFixtureDef(0, 0, 0);
        this.enemyBody1 = PhysicsFactory.createBoxBody(this.mPhysicsWorld, enemy1, BodyType.DynamicBody, enemyFixtureDef1);
        this.enemyBody1.setLinearVelocity(velocity);
        Vector2Pool.recycle(velocity);
        this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(enemy1, this.enemyBody1, true, false));






        this.scene.attachChild(enemy1);

最佳答案

您不能使用MoveModifier移动物理物体,它仅适用于没有PhysicsConnector的Sprite。从Box2D引擎到在其之上工作的AndEngine,连接只有一种方式。您将不得不从物理角度管理汽车的运动,而精灵将跟随身体。并非相反。

10-07 22:37