gpt4 book ai didi

ios - 更改 spritekit 中的初始场景

转载 作者:行者123 更新时间:2023-11-28 08:38:58 29 4
gpt4 key购买 nike

目标:

加载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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com