如何使用MouseDown更改场景

时间:2015-10-02 14:45:22

标签: xcode macos swift sprite-kit

我想创建一个游戏菜单,我得到了类似的东西

class StartGame: SKScene {
    override func didMoveToView(view: SKView) {
        backgroundColor = SKColor.blackColor()
        let startButton = SKSpriteNode(imageNamed: "startGame")
        startButton.position = CGPointMake(size.width/2, size.height/2)
        startButton.name = "startButton"
        addChild(startButton) 
    }

    override func mouseDown(theEvent: NSEvent) {
        if(  ...  )
    }
}

在那里会有更多按钮,例如"保存游戏","退出"等等。还有我的问题。我想通过点击名为" startGame"

的按钮将场景从StartGame更改为GameScene

1 个答案:

答案 0 :(得分:0)

StartGame 中实施mouseDown,如下所示:

override func mouseDown(theEvent: NSEvent) {
    let location = theEvent.locationInNode(self)
    let node = self.nodeAtPoint(location)

    if (node.name == "startButton") {
        let nextScene = GameMenu(size: self.size)
        scene?.view?.presentScene(nextScene, transition: SKTransition.crossFadeWithDuration(1))
    }
}