loops - Looping an A to B animation in Swift -


i'm swift newbie trying loop b positional animation. i'm not sure how reset position animation can loop. appreciated.

import spritekit  class gamescene: skscene {     let cloud1 = skspritenode(imagenamed:"cloud_01.png")     override func didmovetoview(view: skview) {         view.scene!.anchorpoint = cgpoint(x: 0.5,y: 0.5)          cloud1.position = cgpoint(x: -800,y: 0)         cloud1.xscale = 0.5         cloud1.yscale = 0.5          self.addchild(cloud1)          //defining sprite action & repeat          let animatecloud1 = skaction.movetox(800, duration: 1.4);         let repeatcloud1 = skaction.repeatactionforever(animatecloud1)          let group = skaction.group([ animatecloud1,repeatcloud1]);          //running action          self.cloud1.runaction(group);      }      override func update(currenttime: nstimeinterval) {         if(cloud1.position.x == 800){             cloud1.position.x = -800          }     } } 

if understand question correctly, want sprite move , forth between current location , new location specified.

if so, way create 2 animations , put them in sequence. repeat sequence forever.

let animatecloud = skaction.movetox(800, duration: 1.4) let animatecloudbackwards = skaction.movetox(cloud1.position.x, duration: 0) // sequences run each action 1 after another, whereas groups run // each action in parallel let sequence = skaction.sequence([animatecloud, animatecloudbackwards]) let repeatedsequence = skaction.repeatactionforever(sequence)  cloud1.runaction(repeatedsequence)