Search code examples
iosfor-loopcocos2d-iphoneccsprite

For loop CCSprites in CCScene tag check?


I am trying to put together a for loop in Cocos2D app that will loop through all the CCSprite's in my scene checking for sprites with a tag of lets say 2.

Currently I have been trying to do this without any success or even idea where to start because I am not an expert with for loops in Cocos2D since I am not too familiar with its API's.

Do I need to have an if in the for loop? Is that the best thing to do? How should I even accomplish this?


Solution

  • CCArray *arr = [self children];
    
    for(CCSprite *sprite in arr)
    {
        if(2 == sprite.tag)
        {
            //do what you want
        }
    }