场景转换期间崩溃 - Swift 2.0

时间:2016-04-07 13:56:14

标签: ios sprite-kit swift2

所以我开始使用这个太空射击游戏,我创建了一个“EndGame”屏幕,玩家可以点击重启按钮,在他们死亡时返回。问题是,当玩家点击重启时,它只会进入黑色蓝屏并崩溃。错误是

  

主题1:EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP子代码= 0x0)

崩溃线在此功能

func didBeginContact(contact: SKPhysicsContact) {

    let firstBody : SKPhysicsBody = contact.bodyA
    let secondBody : SKPhysicsBody = contact.bodyB

    if ((firstBody.categoryBitMask == PhysicsCatagory.fAsteroids) && (secondBody.categoryBitMask == PhysicsCatagory.Asteroids) || (firstBody.categoryBitMask == PhysicsCatagory.Asteroids) && (secondBody.categoryBitMask == PhysicsCatagory.fAsteroids)){

        if let sprite = firstBody.node as? SKSpriteNode{
        asteroidsHitEachOther((firstBody.node as? SKSpriteNode)!, FuriousAsteroids: (secondBody.node as? SKSpriteNode)!)
        }

    }

    if ((firstBody.categoryBitMask == PhysicsCatagory.Asteroids) && (secondBody.categoryBitMask == PhysicsCatagory.Bullet) || (firstBody.categoryBitMask == PhysicsCatagory.Bullet) && (secondBody.categoryBitMask == PhysicsCatagory.Asteroids)){

        if let sprite = firstBody.node as? SKSpriteNode{
        bulletHitAsteroids((firstBody.node as? SKSpriteNode)!, Bullet: (secondBody.node as? SKSpriteNode)!)
        }

    }
    else if ((firstBody.categoryBitMask == PhysicsCatagory.fAsteroids) && (secondBody.categoryBitMask == PhysicsCatagory.Bullet) || (firstBody.categoryBitMask == PhysicsCatagory.Bullet) && (secondBody.categoryBitMask == PhysicsCatagory.fAsteroids)){

        if let sprite = firstBody.node as? SKSpriteNode{
        bulletHitfAsteroids((firstBody.node as? SKSpriteNode)!, Bullet: (secondBody.node as? SKSpriteNode)!)
        }   

    }

    if ((firstBody.categoryBitMask == PhysicsCatagory.Asteroids) && (secondBody.categoryBitMask == PhysicsCatagory.Fighter) || (firstBody.categoryBitMask == PhysicsCatagory.Fighter) && (secondBody.categoryBitMask == PhysicsCatagory.Asteroids)){

        if let sprite = firstBody.node as? SKSpriteNode{
        fighterGetHit((firstBody.node as? SKSpriteNode)!, Asteroids: (secondBody.node as? SKSpriteNode)!)
        }

    }


    else if ((firstBody.categoryBitMask == PhysicsCatagory.fAsteroids) && (secondBody.categoryBitMask == PhysicsCatagory.Fighter) || (firstBody.categoryBitMask == PhysicsCatagory.Fighter) && (secondBody.categoryBitMask == PhysicsCatagory.fAsteroids)){

        if let sprite = firstBody.node as? SKSpriteNode{
        fighterGetHitHard((firstBody.node as? SKSpriteNode)!, fAsteroids: (secondBody.node as? SKSpriteNode)!)
        }

    }

}

它将“随机”选择要崩溃的线条。它可以崩溃的线是这些线

asteroidsHitEachOther((firstBody.node as? SKSpriteNode)!, FuriousAsteroids: (secondBody.node as? SKSpriteNode)!)

 bulletHitAsteroids((firstBody.node as? SKSpriteNode)!, Bullet: (secondBody.node as? SKSpriteNode)!)

bulletHitfAsteroids((firstBody.node as? SKSpriteNode)!, Bullet: (secondBody.node as? SKSpriteNode)!)

fighterGetHitHard((firstBody.node as? SKSpriteNode)!, fAsteroids: (secondBody.node as? SKSpriteNode)!)

0 个答案:

没有答案