ios - Sprite Kit and Swift, increasing the speed of a node over time? -
ios - Sprite Kit and Swift, increasing the speed of a node over time? -
i have wall generates , moves left (pulls) , i'm curious on if can somehow create overtime gets faster , faster. possible?
here code i'm using pull "wall":
func startmoving() { allow moveleft = skaction.movebyx(-300, y: 0, duration: 0.35) runaction(skaction.repeatactionforever(moveleft)) }
this generates walls in case need know:
var generationtimer: nstimer? func startgeneratingwallsevery(seconds: nstimeinterval) { generationtimer = nstimer.scheduledtimerwithtimeinterval(seconds, target: self, selector: "generatewall", userinfo: nil, repeats: true)
this line of code starts generator
wallgenerator.startgeneratingwallsevery(0.5)
everything works, want know how create starts off slow gets faster overtime (makes harder).
one alternative create variable duration of action , maintain counter increments every time wall pulled. after number of walls have been moved (5 in example), can cut down duration amount.
var duration: nstimeinterval = 0.35 var counter: nsuinteger = 0 func startmoving(duration: nstimeinterval) { allow moveleft = skaction.movebyx(-300, y: 0, duration: duration) runaction(skaction.repeatactionforever(moveleft)) counter += 1 if counter % 5 == 0 { duration -= 0.01 } }
i'm not sure happen if skaction duration negative, may need guard against that.
ios swift skaction
Comments
Post a Comment