我有一个像玩家一样的“蛇游戏”,当身体达到一定长度时移除末端尾部时我遇到了一些问题。现在我有这个:
if (i > maxHealth) {
    id object = [tail objectAtIndex:i-maxHealth-1];
    [tail removeObject:object];//This part doesn't work, if I comment this line out it works but the object is still in the array 
    [self.tileMap removeChild:object cleanup:YES];
}
当i场景初始化时“蛇”的长度i等于 0 并且玩家移动它时“蛇”的长度在哪里,将“尾巴”图像添加到场景和名为tail的 NSMutableArray中。我在调试器中得到了这个:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 4 beyond bounds [0 .. 2]' 
这对我来说没有任何意义,因为在我添加线以从数组中删除精灵并仅用于object从场景中删除精灵之前它工作正常。