我还是很新,但是我几乎完成了一个游戏,问题是我没有允许用户点击“点击播放”的场景,所以当应用程序加载时,用户毫无预兆地被投入游戏。我知道我需要在
下创建场景 override func didMoveToView(view: SKView) {
/* Setup your scene here */
但我似乎无法找到如何做到这一点!我到处寻找,但找不到解决此问题的任何方法,感谢所有帮助,我希望这个问题很清楚,如果没有,我深表歉意!
最佳答案
一个简单的 startScene 过渡到游戏的 gameScene 可能是这样的:
在您的 StartScene 类中为 SKLabelNode
创建一个常量
// you can use another font for the label if you want...
let tapStartLabel = SKLabelNode(fontNamed: "STHeitiTC-Medium")
然后在 didMoveToView
中:
override func didMoveToView(view: SKView) {
// set the background
backgroundColor = SKColor.whiteColor()
// set size, color, position and text of the tapStartLabel
tapStartLabel.fontSize = 16
tapStartLabel.fontColor = SKColor.blackColor()
tapStartLabel.horizontalAlignmentMode = .Center
tapStartLabel.verticalAlignmentMode = .Center
tapStartLabel.position = CGPoint(
x: size.width / 2,
y: size.height / 2
)
tapStartLabel.text = "Tap to start the game"
// add the label to the scene
addChild(tapStartLabel)
}
然后在 touchesBegan
中从 startScene 转到您当前的 gameScene:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let gameScene = GameScene(size: size)
gameScene.scaleMode = scaleMode
// use a transition to the gameScene
let reveal = SKTransition.doorsOpenVerticalWithDuration(1)
// transition from current scene to the new scene
view!.presentScene(gameScene, transition: reveal)
}
要使 StartScene
成为您第一个带有 Tap to play 标签的场景,请在 GameViewController
的 viewDidLoad()
方法中添加此代码:
override func viewDidLoad() {
super.viewDidLoad()
let scene = StartScene(size: view.bounds.size)
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .ResizeFill
skView.presentScene(scene)
}
关于xcode - swift "Start Game Menu",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36240511/