mardi 28 avril 2015

Random Duration in SKAction in Swift

How can I random those two objects’ duration?

  func start() {

    let ajusdtedDuration = NSTimeInterval (frame.size.width / kDefaultXToMovePerSecond)

    let moveLeft = SKAction.moveByX(-frame.size.width/2, y: 0, duration: ajusdtedDuration/2)
    let resetPosition = SKAction.moveToX(0, duration: 0)
    let moveSequence = SKAction.sequence([moveLeft, resetPosition])

    runAction(SKAction.repeatActionForever(moveSequence))
}

func stop() {
removeAllActions()


}

And this is another one. Plus, how can I make both of their duration synced?

  func startMoving() {
let moveLeft = SKAction.moveByX(-kDefaultXToMovePerSecond, y: 0, duration: 1)
    runAction(SKAction.repeatActionForever(moveLeft))
}




Aucun commentaire:

Enregistrer un commentaire