在场景之间移动会因EXC_BAD_ACCESS错误而导致游戏崩溃

时间:2015-05-06 02:35:02

标签: swift sprite-kit exc-bad-access

首先,我想说我的游戏在场景之间移动得很好(第一次)。它从菜单场景开始,现在只有一个按钮,表示玩游戏。

let play = UIButton.buttonWithType(UIButtonType.System) as UIButton
    play.frame = CGRect(x: size.width * 0.5, y: size.height * 0.4, width: 100, height: 100)
    play.setTitle("PLAY GAME", forState: UIControlState.Normal)
    play.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
    play.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
    self.view?.addSubview(play)

func buttonAction(sender:UIButton!)
{
    var gameScene = GameScene(size: self.frame.size)
    var transition = SKTransition.flipVerticalWithDuration(1.0)
    gameScene.scaleMode = SKSceneScaleMode.AspectFill

    let skView = view as SKView!
    skView.presentScene(gameScene, transition: transition)


    play.removeFromSuperview()

}

此按钮将您带到您玩游戏的另一个场景。当你失去这个功能时会被调用。

    func gameOver(){
    let alert = UIAlertView()
    alert.title = "Game Over"
    alert.message = "Score: " + String(score)
    alert.addButtonWithTitle("Okay")
    alert.show()

    var gameStartScene = GameStartScene(size: self.frame.size)
    var transition = SKTransition.flipVerticalWithDuration(1.0)
    gameStartScene.scaleMode = SKSceneScaleMode.AspectFill

    let skView = view as SKView!
    skView.presentScene(gameStartScene, transition: transition)

}

这会让你回到带有播放按钮的第一个场景,但当你按下"玩游戏时#34;再次按钮第二次游戏崩溃与EXC_BAD_ACCESS错误。任何想法??

0 个答案:

没有答案