我正在尝试创建游戏菜单,但我得到了这样的内容
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。
最佳答案
像这样在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))
}
}
关于xcode - 如何使用MouseDown更改场景,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32909813/