Show a SplashScreenScene before to GameScene?
- by lisovaccaro
I want to add a splash screen to my game. I created a SplashScene.sks and a SplashScene.swift file. I'm trying to load my SplashScene before GameScene but I cannot manage to do it.
How should I do this?
This is what I'm trying now:
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let skView = self.view as SKView
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
var scene = SplashScreenScene() // Present SplashScreenScene first
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
Then on my SplashScreenScene:
class SplashScreenScene: SKScene
{
override func didMoveToView(view: SKView) {
self.size = view.bounds.size
self.anchorPoint = CGPointMake(0.5, 0.5)
var background = SKSpriteNode(imageNamed:"LaunchImage")
self.addChild(background)
// Start timer to load next scene
NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("changeScene"), userInfo: nil, repeats: false)
}
func changeScene() {
let scene = GameScene()
view.presentScene(scene)
}
}
This is very close to the solution, however for some reason when I do this my game becomes laggy (if I present GameScene directly the game runs fine).