Spritekit - Transition Scene

I have a main screen with a button, when this button is pressed, it should immediately go to another scene, but it is not. This actually takes a few seconds. Is there a way that I could preload all the nodes in this scene? (Example: on the game loading screen)

This is my code:

let pressButton = SKAction.setTexture(SKTexture(imageNamed: "playButtonP.png"))

            let buttonPressed = SKAction.waitForDuration(0.15)

            let buttonNormal = SKAction.setTexture(SKTexture(imageNamed: "playButton.png"))


            let gameTrans = SKAction.runBlock(){
                let doors = SKTransition.doorsOpenHorizontalWithDuration(0)
                let levelerScene = LevelerScene(fileNamed: "LevelerScene")
                self.view?.presentScene(levelerScene, transition: doors)
            }

        playButton.runAction(SKAction.sequence([pressButton,buttonPressed,buttonNormal,gameTrans]))
+4
source share
1 answer

You can preload SKTexturewhat you use in LevelerScenebefore presenting the scene. Then, as soon as the download is finished, you will present the scene. Here is an example from Apple Documentation translated into Swift:

SKTexture.preloadTextures(arrayOfYourTextures) {
    if let scene = GameScene(fileNamed: "GameScene") {
        let skView = self.view as! SKView
        skView.presentScene(scene)
    }
}

In your case, you have several options:

1. , LevelerScene, GameScene:

class LevelerScene : SKScene {
    // You need to keep a strong reference to your textures to keep
    // them in memory after they've been loaded.
    let textures = [SKTexture(imageNamed: "Tex1"), SKTexture(imageNamed: "Tex1")]

    // You could now reference the texture you want using the array.

    //...
}

GameScene, :

if let view = self.view {
    let leveler = LevelerScene(fileNamed: "LevelerScene") 
    SKTexture.preloadTextures(leveler.textures) {
        // Done loading!
        view.presentScene(leveler)
    }
}

, , GameScene, LevelerScene.

SKScene LevelerScene. GameScene , , LevelerScene .

, , LevelerScene, LevelerScene deinit -ed, . , LevelerScene, .

2. SKTexture.preloadTextures GameViewController , SKScene. (, ), LevelerScene ( - , ).

, SKTexture , . , , , . , , , .

. .

, !

+2

All Articles