random - How to change timeInterval NSTimer in Swift -


i'm new swift, , i'm creating random generated game using nstimer used function timer https://github.com/yuzixun/swift-timer/tree/master/example

my game working fine until got problem speeding game depending on player score using timer, can't change speed of game

my gamescene class :

let mygame = timer.repeat(after: 1) { //my generated game code here }     mygame.start() 

mygame : function generate random object game every second using timer.repeat(after:1).

let levelupdate = timer.repeat(after: 0.1) { //update game , verify player score if(self.score >= 1000 && self.score <= 2500){ // speedup time of game } } 

levelupdate : function update variable game , verify player score every 0.1 second.

my objectif : able change timer of mygame if player reached more 1000 point , speedup mygame 0.8 second, , question possible change time interval of mygame?

please need find way of speeding game player score.

ok, have enough information answer question.

to summarize:

you're using third party library github (link provided) lets create timers in various different ways.

you're using class called timer library, , creating repeating timer method timer.repeat(after:).

you create 2 repeating timers. first runs on 1 second interval , save in constant mygame.

you create repeating timer runs on .1 second interval , save constant called levelupdate.

you want know how change interval of mygame timer.

that kind of description should write. clear, specific, , easy follow.

now answer:

you can't change interval on system class nstimer once it's created.

looking @ library you're using, appears doesn't offer feature either.

what have kill timer , replace new 1 different interval.

you modify library you're using internally if change interval on timer.

failing that, you'd need change mygame var.

you should create method func creategametimer (interval: nstimeinterval) -> nstimer takes timer interval input , creates , returns game timer. way can kill old timer , create new 1 different interval when need that.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -