Show a SplashScreenScene before to GameScene?

Posted by lisovaccaro on Stack Overflow See other posts from Stack Overflow or by lisovaccaro
Published on 2014-08-24T00:44:38Z Indexed on 2014/08/24 4:20 UTC
Read the original article Hit count: 152

Filed under:
|
|

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).

© Stack Overflow or respective owner

Related posts about ios

Related posts about swift