xcode - swift "Start Game Menu"

标签 xcode swift sprite-kit

我还是很新,但是我几乎完成了一个游戏,问题是我没有允许用户点击“点击播放”的场景,所以当应用程序加载时,用户毫无预兆地被投入游戏。我知道我需要在

下创建场景
         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 标签的场景,请在 GameViewControllerviewDidLoad() 方法中添加此代码:

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)

}

它应该是这样的: enter image description here

关于xcode - swift "Start Game Menu",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36240511/

相关文章:

ios - 如何让 iOS navigationItem.titleView 左对齐?

swift - 如何在树莓派 3 上安装 Swift

ios - 如何从 SpriteKit 框架的 SKPhysicsBody 获取六边形形状

ios - Swift - 使用 XCTest 测试包含闭包的函数

objective-c - 在 iOS5 中实现库时获取 "apple mach-o linker id error undefined symbols for architecture i386"

swift - AVCaptureDevicePosition.front 不工作

ios - RTC(Rational Team Concert)与 XCode 集成

ios - 带圆角的 Spritekit 线

swift - 相当于 SpriteKit 中的弹出窗口

swift - 如何构建用于拖放拼图 block 的对齐网格功能?