Hi
Does anyone know the best way to determine if a body has stopped moving; ie turned blue in the model view?
I actually want to know when all bodies have stopped moving and using the body list to test all bodies. I couldn't see any method on world such as isAllBodiesStationary().
Thanks
Graham
Hi
Thanks for your reply. I'll try the is-sleeping method.
I got your 2nd suggestion working using the code below, with _Linear indicating that I could also test rotational components too.
Thanks again.
Graham
=======
public boolean isAllWorldBodiesStationary_Linear()
{
// empty world
int numberBodies = m_world.getBodyCount();
if (numberBodies == 0)
return true;
// traverse body list
Body body = m_world.getBodyList();
Body bodyNext = body;
boolean hasNext = true;
boolean isAllBodiesStatiionary = true;
do
{
Vec2 bodyNextVel = bodyNext.getLinearVelocity();
float len2 = (float)bodyNextVel.lengthSquared();
if (len2 > 0.01f)
{
isAllBodiesStatiionary = false;
break;
}
bodyNext = bodyNext.getNext();
if (bodyNext == null)
{
hasNext = false;
break;
}
} while (hasNext);
if (isAllBodiesStatiionary)
{
return true;
}
return false;
}
I'm glad you got something working. I would still lean toward using the body.isSleeping() line because it's going to be considerably more efficient since the engine has already determined the criteria to put the body to sleep (which you'd be doing again, effectively).