Sunday, February 06, 2011

Box 2D Object runAction/Animate

You can not run any action or animation on a box2D object directly. You have to access the box2D objects userdata (i e CCSprite). Then run the action or animation code on this sprite. This is the code to access the box2D objects sprite-

for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {    
   if (b->GetUserData() != NULL) { 
     CCSprite *sprite = (CCSprite *)b->GetUserData();
     if(sprite.tag==aNumber)
     {
     //Do the action or animation code 
     }
    }
}

Here _world = Your Box2d World
        aNumber = The tag you must set to identify the box2d object when you create them

1 comment:

  1. Thank you for the info. It sounds pretty user friendly. I guess I’ll pick one up for fun. thank u
    ------------------------------------------------------------------------------------
    iPhone Application Development

    ReplyDelete