In which cases runAction on SKNode does not complete?

212 views Asked by At

Are there any known cases where running an SKAction using runAction does not complete?

I launch several 'runAction' on different SKNode. In order to synchronize all these actions, I use a counter that is incremented inside the completion block of each SKAction. When the counter reach the exact number of launched SKAction then the animations is completed.

From time to time one SKAction does not complete then the animation never complete.

// Several actions are launched...
myNode.runAction(myActions,completion:{

    checkCompletion()

})



// Check if all actions completed
//
// numberOfLaunchedActions: number of actions launched
// logDebug: some log helper
func checkCompletion() {

    // This counter is initialized earlier
    numberOfCompletedActions++

    logDebug(">> Actions completed: \(numberOfCompletedActions)/\(numberOfLaunchedActions)")

    if numberOfCompletedActions == numberOfLaunchedActions {
        /// some statements
         logDebug("Animation Completed!")
    }

}

Actions are dynamically generated and are composed of sequence of following actions:

  • waitForDuration
  • scaleTo
  • moveBy
  • hide
  • unhide

No removeFromParent nor runAction nor runBlock.

The action I focus my attention on is the following:

let waitAction = SKAction.waitForDuration(0.4)

let scaleAction = SKAction.scaleTo(0.1, duration: 2.0)
scaleAction.timingMode = .EaseOut

let myAction = SKAction.sequence([
    waitAction,
    scaleAction,
])
1

There are 1 answers

2
Dominique Vial On

There is one known case: adding action after Remove from parent in a sequence: SKAction runAction does not execute completion block

As explained in comment:

Remove from parent is causing the rest of the actions in the sequence not to be called, since the involved node is no longer in the scene. The sequence didn't complete, therefore the completion block shouldn't be called.