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\$
2
  • \$\begingroup\$ What are you trying to do? Why do you need to change the density of an object? \$\endgroup\$
    – knight666
    Jun 13, 2012 at 12:22
  • 3
    \$\begingroup\$ How to ask questions the smart way: ask the goal, not the step. \$\endgroup\$ Jun 13, 2012 at 12:25

1 Answer 1

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\$
1
  • \$\begingroup\$ Yes that I want. Your consideration work perfectly. \$\endgroup\$
    – Siddharth
    Jun 14, 2012 at 5:13

You must log in to answer this question.

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