swift - Set high score as elapsed time in iOS -


the high score in game time based , having trouble setting comparing current score. code far doesn't work:

class gamescene: skscene, skphysicscontactdelegate {  // initialise value current time var currenttime = nsdate() var besttime = nsdate()  override func didmovetoview(view: skview) {      super.didmovetoview(view)      // set current time 0 seconds     var date0 = nsdate();     let timeinterval = floor(date0 .timeintervalsincereferencedate / 60.0) * 60.0     date0 = nsdate(timeintervalsincereferencedate: timeinterval)      currenttime = date0      // call start timer     nstimer.scheduledtimerwithtimeinterval(0.1, target: self, selector: "printduration:", userinfo: nsdate(), repeats: true) 

then

func printduration(timer: nstimer) {     if self.view?.paused == false {         guard let userinfo = timer.userinfo else {             return         }         guard let startdate = userinfo as? nsdate else {             return         }          let duration = nsdate().timeintervalsincedate(startdate)         currenttime = nsdate(timeintervalsincereferencedate: duration)         currenttimevaluelabel.text = "\(nsstring(format:"%3.2f", duration))"     } } 

i want able below able compare time in both variables , set higher 1 accordingly:

if (currenttime > highscore) {     highscore = currenttime     highscorelabel.text = "\(nsstring(format:"%3.2f", highscore))" } 

you can set startdate = nsdate() in didmovetoview() @ beginning , compare 2 see if duration higher typing

if duration > highscore {     highscore = duration } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -