jeudi 25 décembre 2014

Generate random time for subactions inside of repeatActionforever under sequence for SWIFT

Hi I'm trying to generate random time intervals everytime the action is repeated but it only generates the time interval randomly only when the vied did load.


Here is my code :



let moveBucketLeft = SKAction.moveByX(400, y: 0, duration: NSTimeInterval(grabRandomTime()))
let moveBucketRight = SKAction.moveByX(-400, y: 0, duration: NSTimeInterval(grabRandomTime()))
moveBucketLeftAndRight = SKAction.sequence([moveBucketLeft,moveBucketRight])
let repeatMovement = SKAction.repeatActionForever(moveBucketLeftAndRight)
bucket.runAction(repeatMovement)


The method grabRandomTime just generates a random duration between 1 and 5 .


I need all the help I can help. Thank you!





Aucun commentaire:

Enregistrer un commentaire