swift - How to prevent a node from speeding up too much? -


i have nodes fall top of scene , set speed so:

   var droptime: nstimeinterval = 20.5   class gameplayscene: skscene, skphysicscontactdelegate {        droptime = 20.5      runaction(skaction.repeatactionforever(         skaction.sequence([             skaction.runblock(array),             skaction.waitforduration(1.6)])))        func array()  {    let colorcount = 5      let index=int(arc4random_uniform(uint32(colorcount)))      let dots = skspritenode(imagenamed: "color\(index+1)")     dots.position = cgpointmake(150, 600)     dots.physicsbody = skphysicsbody(rectangleofsize: cgsizemake(45, 45))     dots.physicsbody?.dynamic = true     dots.physicsbody?.affectedbygravity = false     in 0..<5 {         dots.physicsbody?.categorybitmask = uint32(0x1 << index)         dots.physicsbody?.contacttestbitmask = uint32(0x1 << index)      }    addchild(dots)               droptime -= 1.09           dots.size = cgsizemake(45, 45)     dots.runaction(         skaction.movebyx(0, y: -1600,             duration: nstimeinterval(droptime)))   } 

}

and time goes on, keep speeding , fall fast gameplay. wondering if there way once reach speed, they'll stay @ speed don't end falling obnoxiously fast , game becomes unplayable.

you put max on drop time.

let mininterval = 5.0 //min interval of 5 sec //mininterval smallest time interval desired - that's how can limit speed droptime = max(droptime - 1.09, mininterval)   

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 -