Get CCNode/CCSprite within FOR statement

79 views Asked by At

I have numerous CCNodes that all have the same query run on them. I am trying to stream line the code and am wondering if its possible to get the CCNodes within a FOR statement.

For example if I had the CCNodes references within a NSArray like

NSArray *exampleArray = @[@"Mercedes-Benz", @"BMW", @"Porsche", @"Opel", @"Volkswagen", @"Audi"];

How would I references them within a FOR Statement?

 for (int i = 0; i <= 30; i++) {

      //Get CCNode reference
}

Is this possible?

1

There are 1 answers

1
tsr On

If your object are added to some parent easiest would be to:

CCNode *node;
CCARRAY_FOREACH(wrapperObject.children, node)
{
  [node runAction:xxx];
}

Within loop you could add condition to check for class of node if you need some constraints.

If you want to create sprites and add them to some parent than you could:

for(int i = 0; i < [exampleArray count]; i++)
{
  CCSprite* sprite = [CCSprite spriteWithFileName:exampleArray[i]];
//set position and other properties
  [parentObject addChild:sprite];
}