ios - 更改 spritekit 中的初始场景

标签 ios iphone swift sprite-kit

目标:

加载Instructions1.swift文件中的场景作为游戏的第一个场景。

我做了什么:

所以我在我的项目中创建了 2 个新文件:Instructions1.sks 和 Instructions1.swift

然后在 GameViewController.swift 中,我将 viewDidLoad 更改如下:

 override func viewDidLoad()
    {
        super.viewDidLoad()

        if let scene = GameScene.unarchiveFromFile("Instructions1") as? GameScene
        {
            // 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 = .AspectFill

            skView.presentScene(scene)
        }
    }

然而,当我加载游戏时,它会直接进入 GameScene.swift。我还在 Instructions1.sks 的自定义类下写了“Instructions1”。不幸的是,仍然没有运气!

非常感谢任何帮助!

谢谢!

最佳答案

您应该更改正在加载的场景的名称。从文件加载 SKScene 时,我还可以使用 init(fileNamed:) 初始化程序。

希望这对您有所帮助!

override func viewDidLoad()
{
    super.viewDidLoad()

    if let scene = Instructions1(fileNamed:"Instructions1")
    {
        // 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 = .AspectFill

        skView.presentScene(scene)
    }
}

关于ios - 更改 spritekit 中的初始场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36876376/

相关文章:

ios - 在加载时选择 Collection View 单元格 - 自定义 UICollectionView 类

iPhone 游戏开发与 Cocos2d : how to generate a cool light effect when an entity gets hit?

json - 如何在 Swift 中访问其标识符根据响应类型而变化的 JSON 响应?

iphone - 在 Objective C 中拥有可变和不可变版本的类(如 NSArray、NSDictionary 等)背后的逻辑是什么?

ios - UIStoryboard 容器将 IBOutlet 附加到父 ViewController

c++ - Objective-C和C++混合编译错误 “_OBJC_CLASS_$_UIResponder”

ios - Google Analytics iOS 广告系列跟踪和 URL 构建器

iphone - 检测 UITableView 节标题之间的距离

ios - Apple Store 审核指南、功能

swift - Swift 3.1 中 `do` block 内的标识符识别