swift - Change time interval in SKAction.waitForDuration() as game goes on -


basically 1 of actions in repeating sequence of actions. each time action gets called in sequence, want waiting time increase, added counter act waiting time number , increment whenever action gets called in sequence. problem this, variable increments when sequence starts, doesn't change @ when action happens again in sequence, waiting time remains constant throughout game. , can't figure out how change when gets called up

var timeinterval = 0 //main method override func didmovetoview(view: skview) {     var scale = skaction.scaleto(5,duration: 2)     sprite = spriteset(texture: sktexture(imagenamed: "texture"), color: uicolor.browncolor(), size: cgsizemake(100,100))     sprite.runaction(skaction.repeatactionforever(skaction.sequence([waitaction,scale,waitaction]))) } //i want time increase each time function called in sequence func waitfunction() -> skaction {     timeinterval++     return skaction.waitforduration(nstimeinterval(timeinterval)) } 

you can use recursive way accomplish want (increment duration of wait parameter):

class gamescene:skscene {      var wait:nstimeinterval = 0      override func didmovetoview(view: skview) {          nslog("start") //using nslog print current time         recursive()      }      func recursive(){          let recursive = skaction.sequence([              skaction.waitforduration(++wait),             //do stuff here, eg. run scale, move...             skaction.runblock({[unowned self] in nslog("block executed"); self.recursive()})             ])          runaction(recursive, withkey: "akey")     } } 

what experiencing, wait action created, initialized , reused in action sequence. have rebuild action each time.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -