从日程表中删除正确的CCSprite

在我解释我的问题之前,我对这个项目的工作做了非常不完整的说明 – 不要拘泥于它的一个整洁的字体的颜色

我的问题是 – 当我想检查损坏的时间到了,我想从数组中删除该对象! 我已经尝试删除它在checkForDamage中,但因为这与ccTime它只是删除每个对象(当我使用removeObjectAtIndex:0摆脱第一个)。 我不能把它放在stopCheckDamage因为当第一个的伤害被检查的时候,玩家不妨放下另一个炸弹。

checkForDamage工作得很好,当用户被击中,我break; 它并调用stopCheckDamage。 我的问题是当用户没有被击中,因为那么不存在的精灵留在数组中,只是弄乱了东西。 我一直在想每一个我知道的方式,如果玩家没有被击中,我似乎无法find一种方法在延迟三秒后删除一个特定的对象。

我还为相关的代码做了一个pastebin,你可以在这里find它

这只是一个想法,

你有一个所有对象的数组。 你只需要知道要删除哪一个。 那么,为什么不给每个对象一个被添加到数组中的tag 。 当你去删除那个对象时,testing它的标签并删除它。

 //Say your array has 10 objects in it, //There will be 10 objects each with a tag 1-10. //When you want to delete an object, 

编辑

 //Before you add each object to the array, use a `for` loop for (int i = 0; i < theMaxNumberOfTagsYouWant; i++) { self.myObject.tag = i; [self.myArray addObject:self.myObject]; //This will loop thru as many times as you want, specify using the //maxNumberOfTagsYouWant variable. and it will give it a tag, which'll be the value of `i` //which gets increased for each object you insert into the array, Then when you want to //remove the object, use the below code to remove the object using it's tag. } -(void)deleteObjectFromArray{ [self.myArray removeObjectAtIndex:myObject.tag]; } 

希望这个对你有帮助。 🙂