swiftsprite-kitsequenceskaction

Run Two Action At The Same Time Inside ONE Sequence


I'm not sure if what I'm seeking is possible, but I'm just checking to make sure I'm not doing thing the hard way.

At the moment I have two sequences, which both run at the same time. Each sequence starts off by waiting 3 seconds and then one sequence scales a node, where the other adjusts that node's alpha. So the code looks something like this:

node.runAction(SKAction.sequence([animationWait, animationScale]))
node.runAction(SKAction.sequence([animationWait, animationAlpha]))

But is there a way of running both the animationScale and animationAlpha at the same time inside one sequence? So it will look something like this (this doesn't work, but I'm hoping you can see what I'm trying to do):

node.runAction(SKAction.sequence([animationWait, (animationScale, animationAlpha)]))

Solution

  • You can group actions together to a sequence:

    var actions = Array<SKAction>()
    
    actions.append(SKAction.sequence([animationWait, animationScale]))
    actions.append(SKAction.sequence([animationWait, animationAlpha]))
    
    let group = SKAction.group(actions)
    
    node.runAction(group)
    

    When the action executes, the actions that comprise the group all start immediately and run in parallel. The duration of the group action is the longest duration among the collection of actions. If an action in the group has a duration less than the group’s duration, the action completes, then idles until the group completes the remaining actions. This matters most when creating a repeating action that repeats a group.