2
\$\begingroup\$

In my game, I want to change density of my body object when it collide with other objects. I found something like following to change density but further I could not able to find any hint for this. So someone please help.

Fixture fixture = goldenBoxArrayList.get(i)
                                        .getGoldenBoxBody()
                                        .getFixtureList().get(0);
                                fixture.setDensity(0.5f);

After setting fixture data I could not able to set it to the body.

EDIT : I want to change my object body density when physics world in simulation

\$\endgroup\$
  • \$\begingroup\$ What are you trying to do? Why do you need to change the density of an object? \$\endgroup\$ – knight666 Jun 13 '12 at 12:22
  • 3
    \$\begingroup\$ How to ask questions the smart way: ask the goal, not the step. \$\endgroup\$ – doppelgreener Jun 13 '12 at 12:25
4
\$\begingroup\$

I'm not sure about AndEngine but in Box2D you can call the following functions:

fixture->SetDensity(5.0f); //this fixture is attached to body below
body->ResetMassData(); //must call this after changing density

AndEngine's physics is just a JNI wrapper around Box2D so it should support all or a subset of Box2D features.

Also check 7.4 Using a Body of Box2D manual, its possible to override mass data calculated from fixtures on a body using:

void SetMassData(const b2MassData* data);
\$\endgroup\$
  • \$\begingroup\$ Yes that I want. Your consideration work perfectly. \$\endgroup\$ – Siddharth Jun 14 '12 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.