SpriteKit: run code or block when activity is removed?

The functionrun

for SKNode

allows you to start the block when the action finishes, but what if the action is canceled / removed viaremoveAllActions?

Canceling an action does not call a completion block from within the function run

.

Is there a callback or a way to run the code when the action is canceled / removed?

+3


source to share


2 answers


Yes, if you delete an activity before it completes, the completion block will not run. Per Docs:



The run (: completion :) method is identical to the run (:) method, but when the action completes, your block is called. This callback is only called if the activity completes. If an activity is removed before it completes, the completion handler is never called.

+1


source


Working around can be:



class YourSpriteNode: SKNode {

     func doSometingAtCompletionAction() {
          //all your stuff
     }

     override removeAllActions() {
         super.removeAllActions()
         doSometingAtCompletionAction()
     }
}

      

+1


source







All Articles