Loading Screen (Not the Splash Screen)

How do you know when to use a loading screen before the game starts? How do you know when you have so many assets that a loading screen is necessary? Do you put it in the scene file? or somewhere else?

Thanks for the help!

The loading screen is more of a smokescreen to keep a user happy while your code and assets load. Whether you need one or not depends a lot on what you are loading but also what you are loading it on. Get your baseline device, the one that you think is going to be slowest, and try it, that is the only accurate way to tell.

You could use a scene file as a loading screen as long as it is simple and loads instantly and will not slow down what you are actually trying to load. Many developers use a simple static image.

One approach is to launch to a loading scene, load your assets and on completion load your first scene for the game. Here is a stripped example to give you an idea of one way you could do that.

import SpriteKit

class LoadingScene:SKScene {  

    // MARK: - Private class properties
    private var timer = NSTimer()

    override func didMoveToView(view: SKView) {
        // Background
        self.backgroundColor = SKColor.blackColor()
    
        self.setup()
    
        self.fireTimer()
    
        self.preloadAssets(completion: {
            self.runAction(SKAction.waitForDuration(2.0), completion: {
                self.loadGameScene()
            })
        })
    }

    private func setup() {
        // Do setup for the Loading Scene
    }

    private func fireTimer() {
        self.timer = NSTimer.scheduledTimerWithTimeInterval(0.25, target: self, selector: #selector(LoadingScene.animateLoadingBar), userInfo: nil, repeats: true)
    }

    func animateLoadingBar() {
        // "Clamp" the xScale to not exceed 100% (1.0)
        if (self.loadingBar.xScale + 0.125) <= 1.0 {
            self.loadingBar.xScale += 0.125
        }
    }


    private func preloadAssets(completion completion: (() -> Void)!) {
        // Load your assets
    
        completion()
    }

    private func loadGameScene() {
        let scene = GameScene(size: kViewSize)
    
        let transition = SKTransition.fadeWithColor(SKColor.blackColor(), duration: 0.25)
    
        self.view?.presentScene(scene, transition: transition)
    }


    deinit {
        self.timer.invalidate()
    }
}