我目前正在教程http://www.raywenderlich.com/25736/how-to-make-a-simple-iphone-game-with-cocos2d-2-x-tutorial。 當忍者之星擊中怪物時,我會遇到一些問題。我的代碼是:Cocos2d:刪除精靈時出現黑屏
- (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,並且它按照它應該記錄的那樣記錄。問題是,當這種情況發生時,它全部變黑。任何想法爲什麼?
[self removeFromParentAndCleanup:YES];在這方面什麼是自我?也許只是可能 – YvesLeBorg 2013-03-07 20:37:57
@YvesLeBorg難道這不是怪物對象嗎? – 2013-03-07 20:42:14
不確定這裏的對象模型是什麼,可能是嵌入遊戲控制器的層。不確定。這聽起來很「腥」,運行一段邏輯的對象在做這項工作的時候會自行刪除。也許OP在主循環之後需要另一個循環來遍歷怪物來刪除和刪除它們。 – YvesLeBorg 2013-03-07 20:44:55