title: Wait until function is completed
body: <p>I have to function for adding two sprites and moving, called Space1 and Space2. I need to make Space1 move Right to Left, after Space 1 is finished the moving. Then, Space2 will move Left to Right.</p>
  
  <p>I can make them move by 2 functions Move1() and Move2(); but they started the same time.
  How can I make the Space2 wait until the function Move1 of Space1 is completed and then Space2 start moving?</p>
  
  <p>This is my code</p>
  
  <pre><code>// Create sprite
          let space1 = SKSpriteNode(imageNamed: "Spaceship")
          space1.position = CGPoint(x: 0, y: frame.height/2)
          space1.xScale = 0.3;
          space1.yScale = 0.3;
          space1.name = "space1";
          self.addChild(space1);
  
          let space2 = SKSpriteNode(imageNamed: "Spaceship")
          space2.position = CGPoint(x: frame.width, y:0)
          space2.xScale = 0.3;
          space2.yScale = 0.3;
          space2.name = "space2";
          self.addChild(space2);
  
          let actualDuration = random(min: CGFloat(1), max: CGFloat(3))
          // Create the actions
          let actionMove1 = SKAction.moveTo(CGPoint(x: frame.width, y: frame.height/2), duration: NSTimeInterval(actualDuration))
  
          let actionMove2 = SKAction.moveTo(CGPoint(x: 0, y: 0), duration: NSTimeInterval(actualDuration))
  
  
          self.runAction(SKAction.sequence([SKAction.runAction(actionMove1, onChildWithName: "space1"),SKAction.runAction(actionMove2, onChildWithName: "space2")]))
  </code></pre>