Moving sprite in Andengine

2.6k views Asked by At

I made a racing game in andengine.The car is moving by MoveModifier().The car is dynamicBody at the same time.But the dynamicBody characteristic of car is losing when it is moving.

(enemy1=car)

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);
1

There are 1 answers

4
JohnEye On

You cannot move physics bodies using MoveModifier, it only works with Sprites without a PhysicsConnector. The connection goes only one way, from the Box2D engine to AndEngine that works on top of it. You will have to manage the car movement in terms of physics and the sprite will follow the body. Not the other way round.