简体   繁体   English

如何在SpriteKit中快速创建启动屏幕

[英]How to create starting screen in SpriteKit with swift

In my game right now I've got a GameScene.swift and a GameOverScene.swift. 现在在我的游戏中,我有一个GameScene.swift和一个GameOverScene.swift。 When the game loads, GameScene.swift shows up and the game plays great. 当游戏加载时,GameScene.swift出现,并且游戏运行良好。 However, now that I'm done with the gameplay, how can I add a start screen that displays when the app opens? 但是,既然我已经完成了游戏玩法,那么如何添加在应用程序打开时显示的开始屏幕?

To create the scene that runs when your app first opens, you will have to make some adjustments to the game's view controller. 要创建在您的应用首次打开时运行的场景,您必须对游戏的视图控制器进行一些调整。 First change 第一次改变

let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene

to

let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! sceneName

and this line in didMoveToView 而didMoveToView中的这一行

if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {

to

if let scene = GameScene.unarchiveFromFile("GameScene") as? sceneName {

This will change the opening scene from GameScene to sceneName, or whatever you called your scene. 这会将打开的场景从GameScene更改为sceneName,或您称为场景的任何内容。 Also, you must declare you scene like this: class sceneName:SKScene {...} . 另外,您必须这样声明场景: class sceneName:SKScene {...} You can create a new .swift file (cmd + n) to score this class in for easy file management or you can put it in the GameScene file. 您可以创建一个新的.swift文件(cmd + n)来评分该类,以便于文件管理,也可以将其放入GameScene文件中。 Happy coding. 快乐的编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM