I have two scenes: Home and Play. The transition to play scene is really slow compared to the transition to home scene. I think this is because there\'s more happing in my p
I do this and works:
in didView of HomeScene put preloadGameScene()
And always in home scene:
fileprivate var nextScene: SKScene?
func preloadGameScene () {
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
self.nextScene = GameScene(fileNamed:"yoursksfilename")
dispatch_async(dispatch_get_main_queue(), { () -> Void in
print("SCENE LOADED")
let loading = self.childNodeWithName("Loading") as? SKLabelNode
self.playButton?.hidden = false
self.playButton?.alpha = 0
//loading?.hidden = true
self.playButton?.runAction(SKAction.fadeAlphaTo(1.0, duration: 0.4))
loading!.runAction(SKAction.fadeAlphaTo(0.0, duration: 0.4))
})
})
}
goToGameScene()
is called by a button personal SKButton class:
func goToGameScene () {
guard let nextScene = nextScene else {return}
let transition = SKTransition.crossFadeWithDuration(0.5)
nextScene.scaleMode = .AspectFill
scene!.view?.presentScene(nextScene, transition: transition)
}
UPDATE SWIFT 3
fileprivate var nextScene: SKScene?
func preloadGameScene () {
let qualityOfServiceClass = DispatchQoS.QoSClass.background
let backgroundQueue = DispatchQueue.global(qos: qualityOfServiceClass)
backgroundQueue.async(execute: {
self.nextScene = GameScene(fileNamed:"yoursksfilename")
DispatchQueue.main.async(execute: { () -> Void in
print("SCENE LOADED")
let loading = self.childNode(withName: "Loading") as? SKLabelNode
self.playButton?.isHidden = false
self.playButton?.alpha = 0
//loading?.hidden = true
self.playButton?.run(SKAction.fadeAlpha(to: 1.0, duration: 0.4))
loading?.run(SKAction.fadeAlpha(to: 0.0, duration: 0.4))
})
})
}