开发者

Deleting CCSprites stored in NSMutableArray not working right

Here is what I've tried.

In m开发者_运维百科y init method I initialized the array:

deleteSprites = [[NSMutableArray alloc] initWithCapacity:500];

This is how I added them to the array:

CCSprite *SpriteSave;
SpriteSave = [CCSprite spriteWithBatchNode:Batch rect:CGRectMake(0,0,6,6)];
[Batch addChild:SpriteSave];
[deleteSprites addObject:SpriteSave];

This is how I attempt to remove the sprites:

delCount = 0;
while (delCount < [deleteSprites count])
    CCSprite *delSprite = (CCSprite *) [deleteSprites objectAtIndex:delCount];
    [delSprite.parent removeChild:delSprite cleanup:YES];
    delCount++;
}
[deleteSprites removeAllObjects];

This causes some of the sprites to flip, but they still appear on screen and none are deleted. I've already researched everywhere and although I made my code very similar to others that got it to work, it still won't work for me. I've also already read through the memory management documents and I still don't see what I'm doing wrong. Also I've tried adding the sprites to the userdata of the fixtures they're supposed to be representing and when the fixture is destroyed I once again try to remove the sprite but the same thing happens. Please Help!.

I figured out what it was. I was making a logical error in a few of my if statements and accidentally added the sprites twice. Sorry about that everyone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜