I already know how to run multiple animations on the same SKSpriteNode at once:
createPaths()
let myIcon1 = MyIcon(wIcon: "screen", iSize: iSize)
let move = SKAction.follow(iconPath[0], asOffset: false, orientToPath: false, duration: 1)
let shrink = SKAction.resize(byWidth: -iSize.width/2, height: -iSize.width/2, duration: 1)
let blur = SKAction.fadeAlpha(to: 0.6, duration: 1)
let group = SKAction.group([shrink, move, blur])
myIcon1.run(group)
But I have two more icons I would like to animate at the same time.
Granted, with just 3 icons total I din't see any lag if I do something like this:
myIcon1.run(group1)
myIcon2.run(group2)
myIcon3.run(group3)
But surely there is a proper way to do this?
The proper way is to do exactly as you did.
From the phrasing of the question, it sounds like maybe you were expecting myIcon1.run(group1)
to finish before myIcon2.run(group2)
. If so, that's not the way that running actions works. The run
is just telling the sprite what to be doing, not actually doing it immediately.
By analogy, think of yourself as a film director. You tell your actors (the sprites) what to do before the scene starts. When you say "Action!" (i.e., the update loop starts running) all the sprites start doing whatever you told them, but they're doing it independently. Most of SpriteKit programming is structuring your app as reactions to things that happen as the scene plays out. You can tell sprites to do something new whenever they finish their previous tasks (by having a completion block argument to run
), tell them to stop whatever they're doing and do something else (cancel actions, add new ones), or have them react when external events happen (e.g., you get collision notifications from the physics engine or the user touches the screen).