我使用 spritekit 和 swift 在 xcode 中创建了一个非常简单的游戏。我已经完成了实际游戏本身的编码。现在我想创建一个主菜单,这样当游戏打开时,就会有一个菜单,其中包含进入设置或开始游戏的按钮。我不知道我该怎么做。我应该使用 Storyboard吗?如果是这样,我如何在 xcode 中实现它。谢谢大家:)
最佳答案
swift 3.0
import SpriteKit
class MenuScene: SKScene {
var playButton = SKSpriteNode()
let playButtonTex = SKTexture(imageNamed: "play")
override func didMove(to view: SKView) {
playButton = SKSpriteNode(texture: playButtonTex)
playButton.position = CGPoint(x: frame.midX, y: frame.midY)
self.addChild(playButton)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let pos = touch.location(in: self)
let node = self.atPoint(pos)
if node == playButton {
if let view = view {
let transition:SKTransition = SKTransition.fade(withDuration: 1)
let scene:SKScene = GameScene(size: self.size)
self.view?.presentScene(scene, transition: transition)
}
}
}
}
}
关于ios - 如何在 xcode 中为使用 swift 制作的 spritekit 游戏创建主菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31888885/