Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode Swift";“开始游戏菜单”;_Xcode_Swift_Sprite Kit - Fatal编程技术网

Xcode Swift";“开始游戏菜单”;

Xcode Swift";“开始游戏菜单”;,xcode,swift,sprite-kit,Xcode,Swift,Sprite Kit,我还是一个新手,但是我几乎完成了一个游戏,问题是我没有一个场景允许用户点击“点击播放”,所以当应用程序加载时,用户只是在没有警告的情况下进入游戏。我知道我需要在下面创建场景 override func didMoveToView(view: SKView) { /* Setup your scene here */ 但我似乎找不到如何做到这一点!我到处都找过了,但是找不到任何可以解决这个问题的方法,非常感谢大家的帮助,我希望这个问题是清楚的,如果没有,我道歉

我还是一个新手,但是我几乎完成了一个游戏,问题是我没有一个场景允许用户点击“点击播放”,所以当应用程序加载时,用户只是在没有警告的情况下进入游戏。我知道我需要在下面创建场景

         override func didMoveToView(view: SKView) {
        /* Setup your scene here */

但我似乎找不到如何做到这一点!我到处都找过了,但是找不到任何可以解决这个问题的方法,非常感谢大家的帮助,我希望这个问题是清楚的,如果没有,我道歉

一个简单的startScene,可以过渡到游戏场景,如下所示:

在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)
}
然后在
触摸中开始从startScene进入当前游戏场景:

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的帮助。我创建了一个新的swift文件“StartScene.swift”,除了我把你给我的代码放在GameSecene.swift文件中。我如何使“点击播放”成为我出现的第一个场景?再次谢谢你!!欢迎光临,我在回答中添加了
GameViewController
的初始设置,使带有“点击播放”标签的
StartScene
成为我现在得到的第一个场景。使用未解决的缩进“StartScene”错误。您是否命名了类声明
class StartScene:SKScene{…
在StartScene.swift中,就像您在GameViewController中创建的一样?如果有输入错误,您将得到一个未解决的标识符的错误。我看到了,谢谢!所有东西都在我需要的地方,但是它没有显示“点击播放”场景中,当它加载时,我只是看到一个灰色的屏幕。我强烈推荐。它有很多很好的架构决策,有几个可重用的组件。
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)

}