我在andengine中做了一个赛车游戏,通过MoveModifier(),汽车在运动。汽车同时是dynamicBody,但是运动时汽车的dynamicBody特性会丢失。
(敌人 1=汽车)
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);