我正在研究一個cocos2d項目,並希望使用一組精靈。從NSMutable陣列中刪除精靈
我創建數組:
NSMutableArray *ssprites;
然後我在init方法中添加的東西給它:
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];
再後來我想刪除精靈:
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];
}
}
但由於某些原因,精靈正停留在屏幕上。我應該如何修復代碼才能真正刪除精靈?
'I <[ssprites數]'然後'[ ssprites removeObjectAtIndex:i]'會導致問題。 – Joe
我在代碼中找不到任何錯誤,也許您必須查看代碼的其他部分。 –