NEW! Master Swift design patterns with my latest book! >>

How to run SKActions in a group

Paul Hudson       @twostraws

SpriteKit action groups let you run multiple SpriteKit actions simultaneously. The grouped actions become a new action that can go into a sequence, and SpriteKit automatically ensures all actions in a group finish before the sequence continues.

The code below makes a spaceship shrink down to 10% of its original size while fading out, with both actions happening at the same time:

let sprite = SKSpriteNode(imageNamed:"Spaceship")

let scale = SKAction.scale(to: 0.1, duration: 0.5)
let fade = SKAction.fadeOut(withDuration: 0.5)
let group = SKAction.group([scale, fade])

sprite.run(group)

Available from iOS 7.0 – see Hacking with Swift tutorial 17

Did this solution work for you? Please pass it on!

Other people are reading…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Learn Swift faster!

Take your Swift learning to the next level: buy the Hacking with Swift e-book and get bonus material to help you learn faster!

MASTER SWIFT NOW
Buy Practical iOS 12 Buy Pro Swift Buy Swift Design Patterns Buy Practical iOS 11 Buy Swift Coding Challenges Buy Server-Side Swift (Vapor Edition) Buy Server-Side Swift (Kitura Edition) Buy Hacking with macOS Buy Advanced iOS Volume One Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with Swift Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let me know!

Click here to visit the Hacking with Swift store >>