我目前正在做教程http://www.raywenderlich.com/25736/how-to-make-a-simple-iphone-game-with-cocos2d-2-x-tutorial。当忍者星击中怪物时,我的反应部分有问题。我的代码是:
- (void)update:(ccTime)dt {
NSMutableArray *projectilesToDelete = [[NSMutableArray alloc] init];
for (CCSprite *projectile in _projectiles) {
NSMutableArray *monstersToDelete = [[NSMutableArray alloc] init];
for (CCSprite *monster in _monsters) {
if (CGRectIntersectsRect(projectile.boundingBox, monster.boundingBox)) {
[monstersToDelete addObject:monster];
}
}
for (CCSprite *monster in monstersToDelete) {
[_monsters removeObject:monster];
[self removeFromParentAndCleanup:YES];
}
if (monstersToDelete.count > 0) {
[projectilesToDelete addObject:projectile];
}
[monstersToDelete release];
}
for (CCSprite *projectile in projectilesToDelete) {
[_projectiles removeObject:projectile];
[self removeChild:projectile cleanup:YES];
}
[projectilesToDelete release];
}
这工作正常,不会崩溃,但是当我用弹丸击中怪物时,模拟器上的屏幕变黑。没有错误或任何东西。我记录了 CGRectIntersectRect,它按原样记录。问题是,当这种情况发生时,一切都会变黑。知道为什么吗?