0
votes

What is the better approach:

For example if I want to add a node to the scene and play some animation, or run some other code which I want to execute right after the node is added to the scene, but not before, what is a preferred thing to do:

This:

[scene addItem:item];
[item playAnimation];
[item runSomeTimeRelatedCode];

or to run this same code within action with completion block:

 SKAction *action = [SKAction runBlock:^{
       [scene addItem:item];

    }];
    [scene runAction:action completion:^{
       [item playAnimation];
       [item runSomeTimeRelatedCode];
    }];
1

1 Answers

0
votes

The second code fragment just needlessly delays execution and makes the code more complex to write. In short, it makes no sense to use it.