碰撞当前有效,我可以玩我的游戏一段时间但是大约50个左右的敌舰被摧毁后我得到错误EXC_BREAKPOINT(代码= 1,子代码= 0x1003f42cc)
我在这行代码上得到它
projectileDidCollideWithEnemy(firstBody.node as SKSpriteNode, enemy: secondBody.node as SKSpriteNode)
以下是我认为影响它的代码,以及断点导致的代码。
func didBeginContact(contact: SKPhysicsContact) {
var firstBody: SKPhysicsBody
var secondBody: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
firstBody = contact.bodyA
secondBody = contact.bodyB
}
else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
if ((firstBody.categoryBitMask & PhysicsCategory.Enemy != 0) &&
(secondBody.categoryBitMask & PhysicsCategory.Projectile != 0)) {
projectileDidCollideWithEnemy(firstBody.node as SKSpriteNode, enemy: secondBody.node as SKSpriteNode)
}
这是被称为
的函数func projectileDidCollideWithEnemy(projectile:SKSpriteNode, enemy:SKSpriteNode) {
projectile.removeFromParent()
enemy.removeFromParent()
score++
scorelabel.text = String(score)
}
答案 0 :(得分:0)
你可能想要在projectileDidCollideWithEnemy中移除射弹和敌人之前尝试检查父级是否为非。