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

Adding iAd and AdMob in your Cocos 2D Game

iAd is allowed in ios4.0 or later versions. If you want both iAd and AdMob to run on your game depending on ios. If ios < 4 then show AdMob else show iAd.

Go to this link-
http://www.cocos2d-iphone.org/forum/topic/8424

Here you will find the best example how to do it.