0

In my game I used Physics editor for a sprite. And I scaled it to large size like this

 sprite.setScale(screenwidth/20 / sprite.getWidth());

and added it to the physics body like this

 Body = PhysicsFactory.createBoxBody(physicsWorld, sprite, BodyType.DynamicBody, FIXTURE_DEF);

Now in the game, the sprite looks large as it is scaled, but the physics body attached to it is small.(did not increase size as scaled).

So now what to do to scale the body itself. Please suggest me some ideas.

Sandeep R
  • 2,284
  • 3
  • 25
  • 51

1 Answers1

0
  1. First, insert the following fixture definition into the onPopulateScene() method:

    FixtureDef BoxBodyFixtureDef =
    PhysicsFactory.createFixtureDef(20f, 0f, 0.5f);
    
  2. Next, place the following code that creates three rectangles and their corresponding bodies after the fixture definition from the previous step:

    Rectangle staticRectangle = new Rectangle(cameraWidth /
    2f,75f,400f,40f,this.getVertexBufferObjectManager());
    staticRectangle.setColor(0.8f, 0f, 0f);
    mScene.attachChild(staticRectangle);
    PhysicsFactory.createBoxBody(mPhysicsWorld, staticRectangle,
    BodyType.StaticBody, BoxBodyFixtureDef);
    
    Rectangle dynamicRectangle = new Rectangle(400f, 120f, 40f, 40f,
    this.getVertexBufferObjectManager());
    dynamicRectangle.setColor(0f, 0.8f, 0f);
    mScene.attachChild(dynamicRectangle);
    Body dynamicBody = PhysicsFactory.createBoxBody(mPhysicsWorld,
    dynamicRectangle, BodyType.DynamicBody, BoxBodyFixtureDef);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(
    dynamicRectangle, dynamicBody);
    
    Rectangle kinematicRectangle = new Rectangle(600f, 100f,
    40f, 40f, this.getVertexBufferObjectManager());
    kinematicRectangle.setColor(0.8f, 0.8f, 0f);
    mScene.attachChild(kinematicRectangle);
    Body kinematicBody = PhysicsFactory.createBoxBody(mPhysicsWorld,
    kinematicRectangle, BodyType.KinematicBody, BoxBodyFixtureDef);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(
    kinematicRectangle, kinematicBody);
    
  3. Lastly, add the following code after the definitions from the previous step to set the linear and angular velocities for our kinematic body:

kinematicBody.setLinearVelocity(-2f, 0f);
kinematicBody.setAngularVelocity((float) (-Math.PI));

Izu
  • 235
  • 1
  • 5
  • yeah I registered physics connecter but the scaling is not working. – Sandeep R May 12 '14 at 04:20
  • i updated my answer with the official tutorial steps, maybe complain it with your implementation and if there is nothing wrong, you should contact andengine support – Izu May 12 '14 at 07:56