Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
    
What are you trying to do? Why do you need to change the density of an object? –  knight666 Jun 13 '12 at 12:22
2  
How to ask questions the smart way: ask the goal, not the step. –  Jonathan Hobbs Jun 13 '12 at 12:25
add comment

1 Answer

up vote 1 down vote accepted

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);
share|improve this answer
    
Yes that I want. Your consideration work perfectly. –  Siddharth Jun 14 '12 at 5:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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