NSMutableArray,添加精灵并删除最后一个对象(最后添加的精灵)?

时间:2012-05-06 20:17:47

标签: cocoa cocos2d-iphone

-(void)createSprite{

CCSprite *shotV = [CCSprite spriteWithFile:@"green.png"];

[self addChild:shotV z:1];

[shotVArray addObject:shotV];
NSlog(@"%@",shotV);

}     
-(void)aSpecialCase{

[self removeChild:[shotVArray lastObject] cleanup:YES];

}

我没有让这个工作。 函数“createSprite”会弹出sprite。 “在aSpecialCase中”我想删除最后创建的精灵。还希望删除它将结束该实例的当前CCSequence。

1 个答案:

答案 0 :(得分:1)

-(void)aSpecialCase{
[self removeChild:[shotVArray lastObject] cleanup:YES];
}

这只会从图层中删除精灵..不会将其从数组中删除...

更好的方法是......

-(void)aSpecialCase{
  CCSprite *sprite  = [pshotVArray lastObject];
  [self removeChild:sprite cleanup:YES];
  [pshotVArray removeObject:sprite];
}

希望这会有所帮助.. :)