我正在制作一款游戏,而部分游戏则是一只收集鸡蛋的兔子。当兔子与蛋相撞时,我遇到了一个问题,那就是游戏崩溃。我得到的错误是收集< __NSArrayM:0x17805eed0>被列举时发生了变异。'碰撞后删除对象
我有一个鸡蛋的图像,鸡蛋出现在每两秒钟后,当兔子相交的鸡蛋时,我只想让鸡蛋消失并给予1分。
这里是我使用
在头文件中的代码,我有
@property (strong, nonatomic) NSMutableArray *eggs;
和实现文件我有这个添加鸡蛋
UIImageView *egg = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth([[self gameView] frame]), holeBottom - 115 , 50, 60)];
[egg setImage:[UIImage imageNamed:@"easterEgg.png"]];
[[self gameView] insertSubview:egg belowSubview:[self counterLabel]];
[[self eggs] addObject:egg];
而这个检测碰撞并试图移除鸡蛋
for (UIView *egg in [self eggs]) {
[egg setFrame:CGRectOffset([egg frame], [link duration]*FBSidewaysVelocity, 0)];
if (CGRectIntersectsRect (rabbit.frame, CGRectInset ([egg frame], 8, 8))) {
[[self eggs]removeLastObject];
[self incrementCount];
}
}
我希望你能看到我的代码出错了,并帮助我纠正这个问题。
预先感谢您的宝贵时间
你是最棒的! @Bryan Chen非常感谢你的配偶,它的工作非常完美。 – user2632573