Hung Teoh
Hung Teoh

Reputation: 13

In-game tutorial in sprite kit game using swift

I created a game and I want to teach the player how to play this game. So i'm planning to create a in-game tutorial where the gameplay will be paused and display some instructions to the players to teach them. I want this in-game tutorial to be run just once. How can I do that ?

Upvotes: 1

Views: 91

Answers (1)

Jarron
Jarron

Reputation: 1049

You can use a UserDefault boolean to determine whether code needs to be executed. Use an 'If Statement' to see if the boolean is equal to false, and if so run the tutorial and then set the UserDefault boolean to true.

func hasTutorialBeenExecuted() {

    let defaults = UserDefaults.standard

    if defaults.bool(forKey: "tutorialExecuted") == false {

        print("Run Tutorial")

        defaults.set(true, forKey: "tutorialExecuted")

    }

}

Upvotes: 3

Related Questions