I am working on a cocos2d project and want to work with an array of sprites.
I create the array:
NSMutableArray *ssprites;
Then I add stuff to it in the init method:
CCSprite *obssprite = [CCSprite spriteWithFile:@"/Users/Desktop/Programs/physics test/physics test/Resources/[email protected]"];
obssprite.position=ccp(position,5);
[self addChild: obssprite];
[ssprites addObject: obssprite];
Then later I want to remove sprites:
for( int i=0; i<[ssprites count];i++) {
CCSprite *spr = (CCSprite *) [ssprites objectAtIndex:i];
if(YES) { //this is just for test, the actual program uses an actual condition
[spr removeFromParentAndCleanup: YES];
[ssprites removeObjectAtIndex:i];
}
}
But for some reason the sprites are staying on the screen. How should I fix the code to actually remove the sprites?
i < [ssprites count]and then[ssprites removeObjectAtIndex:i]will cause issues. - Joe