How to iterate through a CCArray ?

How to iterate through a CCArray ?
0.0 0



Here is an example of code to iterate through a CCMutableArray (“sprites” being a CCMutableArray of CCSprites):

CCMutableArray::CCMutableArrayIterator it;

for (it = sprites->begin(); it != sprites->end(); it++) {
    CCSprite *sprite = *it;
    // process the sprite

What is the equivalent code to iterate through a CCArray ?



Why do you want to use CCArray?


Because I get a CCArray with the method getChildren() from the class CCNode.

So I wrote the following:

 for(int i = 0; i < myNode->getChildren()->count(); i++)
        CCNode *child = myNode->getChildren()->objectAtIndex(i);
        //some more code hereafter...

I don’t know yet if it works but it should be ok… (very simple code ; easier than Iterators used on CCMutableArrays)

If somebody has some other kind of code, let me know !


Perhaps something like this would work:

CCObject* obj;
    //do something. static cast up to do more


Hey andre did it worked for you?