I am developing a game using jbox2d in conjunction with jBox2d for android. I would like to detect if user touches a particular dynamic body among various bodies in my world. I have tried iterating over all the bodies and find one of my interest but it didnt work for me. Please help Heres what I did :
@Override
public boolean ccTouchesEnded(MotionEvent event)
{
CGPoint location = CCDirector.sharedDirector().convertToGL(CGPoint.ccp(event.getX(),
event.getY()));
for(Body b = _world.getBodyList();b.getType()==BodyType.DYNAMIC; b.getNext())
{
CCSprite sprite = (CCSprite)b.getUserData();
if(sprite!=null && sprite instanceof CCSprite)
{
CGRect body_rect = sprite.getBoundingBox();
if(body_rect.contains(location.x, location.y))
{
Log.i("body touched","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
expandAndStopBody(b);
break;
}
}
}
return true;
}
After the touch, system continues to print GC_CONCURRENT freed 1649K, 14% free 11130K/12935K, paused 1ms+2ms and everything goes to hung like state.