我一直得到"线程1:EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)"

时间:2018-04-05 05:41:59

标签: ios swift sprite-kit skspritenode

我对swift编码很新,需要一些帮助。我正在制作一个应用程序,其中随机彩色气球节点在屏幕上升起并弹出它们但是如果你错过某种颜色的节点,游戏应该结束。但是,当错误的彩色气球离开屏幕时,我无法使游戏结束。我试图比较气球的y位置和位于屏幕顶部的节点的y位置" bounds"但是当我运行代码Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)时,我一直收到此错误。这就是我现在所拥有的:

@objc func endGameWhenBalloonOut() {
    let Bounds = childNode(withName: "bounds")
    let redBalloon = childNode(withName: "RedBalloon")
    if childNode(withName: "redIndicator")?.zPosition == 5 &&   Double((redBalloon?.position.y)!) > Double((Bounds?.position.y)!)    {
         if let scene = GameOverSceneClass(fileNamed: "GameOver") {
              // Set the scale mode to scale to fit the window
              scene.scaleMode = .aspectFill
              // Present the scene
              view!.presentScene(scene, transition: SKTransition.doorsOpenHorizontal(withDuration: 1))
              self.isPaused = true
              self.removeAllChildren()
              self.removeAllActions()
              self.scene?.removeFromParent()
         }
    }
}

0 个答案:

没有答案