Domanda

For example: I made this array to keep all my CCSprites:

CCSprite *Enemy[20];

I figured it would be okay, since I would have no more than 20 enemies, but now I want to be able to increase the size of it, once it's filled with objects, to be 40.

È stato utile?

Soluzione

NSMutableArray *mySprites = [[NSMutableArray alloc] init];


// array is mutable so you can add to it
[mySprites addObject: newSprite];

// objective c syntax has improved, you can now access elements with the following syntax
CCSprite *mySprite = mySprites[0];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top