ios - How do I save the number of times the user has lost the game in Swift? -
so every-time user loses game want add 1. want save number of deaths user has in game. right number stays @ 1 , doesn't go when user loses again. why happen?
override func didmovetoview(view: skview) { var deathlabel = sklabelnode() deathlabel = sklabelnode(fontnamed: "ladyice-3d") deathlabel.text = "100" deathlabel.zposition = 14 deathlabel.fontsize = 100 deathlabel.fontcolor = skcolor.darktextcolor() deathlabel.position = cgpointmake(self.size.width / 1.1, self.size.height / 1.4) deathlabel.hidden = true self.addchild(deathlabel) } //edit if firstbody.categorybitmask == herocategory && fourthbody.categorybitmask == gameovercategory { var deathscore: int = 0 deathscore++ deathlabel.hidden = false var defaults=nsuserdefaults() var savedeaths = defaults.integerforkey("savenumberofdeaths") if(deathscore > savedeaths) { defaults.setinteger(deathscore++, forkey: "savenumberofdeaths") } var shownumberofdeaths =defaults.integerforkey("savenumberofdeaths") deathlabel.text = string(shownumberofdeaths) }
for saving simple values nsuserdefaults
choice.
the setinteger:forkey:
method meet needs.
Comments
Post a Comment