I was looking at PhysicsExample from AndEngine's Examples. I made the following change that I added a vertical line shape and created a fixture for it. Then I registered a rotation modifier for that shape. It is rotating properly but not updating its physics properties on rotation means when it is rotating and any physics body hits it, it did not give collision effect. Here is my code:

final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
        final Rectangle ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2, vertexBufferObjectManager);
        final Rectangle roof = new Rectangle(0, 0, CAMERA_WIDTH, 2, vertexBufferObjectManager);
        final Rectangle left = new Rectangle(0, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);
        final Rectangle right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);
        final Rectangle center1 = new Rectangle((CAMERA_WIDTH/2) - 2, (CAMERA_HEIGHT/2) - 100, 10, 200, vertexBufferObjectManager);
        final Rectangle center2 = new Rectangle((CAMERA_WIDTH/2) - 100, (CAMERA_HEIGHT/2) - 2, 200, 10, vertexBufferObjectManager);

        center1.registerEntityModifier(new LoopEntityModifier(new RotationModifier(2, 0, 360)));

        final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, center1, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, center2, BodyType.StaticBody, wallFixtureDef);

Although the body give collision effect when it reaches the shapes initial position. I am new to AndEngine. Where I a wrong...???


1 Answer 1


You are only rotating the Shape, not the physics body. The Shapes follow the movement of the physics bodies of Box2D, not the other way round.

  • \$\begingroup\$ So how to rotate the physics body? \$\endgroup\$ Commented Aug 9, 2012 at 11:17
  • \$\begingroup\$ Either body.setTransform(x, y, angle) to just set the rotation angle or body.applyAngularImpulse(impulse) or body.applyTorque(torque) to make the body rotate. \$\endgroup\$
    – JohnEye
    Commented Aug 9, 2012 at 11:22
  • \$\begingroup\$ Are there available modifiers for physics bodies as we have for entities which can modify physics body properties continuously? \$\endgroup\$ Commented Aug 9, 2012 at 11:31
  • \$\begingroup\$ Not that I know of. You can perform some checks in onUpdate() though, for example look if the body is rotating properly and give it a little nudge or slow it down a bit. \$\endgroup\$
    – JohnEye
    Commented Aug 9, 2012 at 11:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .