简体   繁体   中英

How to create starting screen in SpriteKit with swift

In my game right now I've got a GameScene.swift and a GameOverScene.swift. When the game loads, GameScene.swift shows up and the game plays great. 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

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. Also, you must declare you scene like this: 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. Happy coding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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