0

I'm making a JewelDash type game. For some reason after a while, 1 sprite which was supposed to be removed from the scene didn't. That sprite won't respond to touch, nothing, it just there. Hangout underneath other newly created sprites. What might be the cause of this?

I added all my sprites into a spritesArray. Whenever user touch a block, I loop through spritesArray and identify which sprite was touched. The fact that it doesn't respond to touch telling me that it was removed from spritesArray

This happens when many sprites get removed at the same time. And rarely happen.

Thanks.

4

1 回答 1

1

如果您使用的是 NSMuttableArray,则可能会发生您没有分配 init spritesArray 的情况,因此在添加任何精灵之前在 init 方法中分配初始化它有时这发生在我身上,所以我无法访问任何精灵,因为数组未初始化。我得到我的数组 nil

也将孩子从自我中移除

[spritesArray removeObject:sprite name];
[self removeChild:sprite name cleanup:YES];

试试这个可能会有所帮助

于 2013-02-20T05:43:26.787 回答