swift3 - How to create highscores in swift 3 with the spritekit technology -


i trying implement highscore mechanic game working on, tutorials online using uikit instead of spritekit. wondering whether or not put code score in gameviewcontroller or gamescene.swift

i'd imagine place you're keeping track of score particular "play" of game in scene, makes sense.

what need decide how save high score. basic approach use userdefaults.

so when game ends can save score this:

let defaults = userdefaults.standard defaults.set(100, forkey: "highscore") 

that set value "highscore" key whatever specify (in above example 100).

of course, you'll need make sure score higher pervious higher one. can load in previous high score this:

if let highscore = defaults.value(forkey: "highscore") {   if score > highscore {     defaults.set(100, forkey: "highscore")   } } 

you can load in "highscore" value anywhere in app. view controller or scene.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -