0

I am working on an Xcode playground in Swift and I would like for a selection of sprites to perform some actions in a set order, one after the other. However they appear to be happening all at once, despite my use of the completion handler.

Any while loops I try (using a boolean to see if the action is completed or not - set to true in the completion handler) result in an infinite loop.

Here is a code I've tried:

centreOfRotation.run(SKAction.rotate(byAngle: CGFloat(degreesToRadians(angleInDegrees)), duration: 5), completion: {
        finished = true
        print("finished")
})

But this code doesn't wait for completion before going to the next line.

Does anyone know how to stop this? Thanks.

JCode
  • 1
  • 1
  • Note that however once it is done, it executes the print statement. Additionally, I require these statements to be mixed and matched - so I can't just put my next action in the completion section! Thanks. – JCode Mar 25 '18 at 12:48
  • "I would like for a selection of sprites to perform some actions in a set order, one after the other." Use the action sequence. – El Tomato Mar 25 '18 at 13:10
  • Hi El Tomato, I have tried this however the problem is that I would like the sequence of actions to be across multiple different sprites. Not just the same one. – JCode Mar 25 '18 at 13:29
  • I also need to be able to use this action again (without retyping the whole thing) and have a different next action. – JCode Mar 26 '18 at 06:24

0 Answers0