Swift version: 5.2
One of the great features of SpriteKit's actions is that they can be chained together using action sequences. SpriteKit automatically ensures each action finishes before the next one begins – all you need to do is create the actions then put them into an array.
The example below makes a spaceship shrink down to 10% of its original size before fading out:
let sprite = SKSpriteNode(imageNamed:"Spaceship") let scale = SKAction.scale(to: 0.1, duration: 0.5) let fade = SKAction.fadeOut(withDuration: 0.5) let sequence = SKAction.sequence([scale, fade]) sprite.run(sequence)
SPONSORED Are you tired of wasting time debugging your Swift app? Instabug’s SDK is here to help you minimize debugging time by providing you with complete device details, network logs, and reproduction steps with every bug report. All data is attached automatically, and it only takes a line of code to setup. Start your free trial now and get 3 months off exclusively for the Hacking with Swift Community.
Available from iOS 7.0 – see Hacking with Swift tutorial 14
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.