2

I have a game where I use a lot of SKActions to deliver the desired game logic.

For example, instead of setting the zRotation of a sprite to a value, I would use runAction(SKAction.rotateTo(/* angle here */, duration: 0.0) instead.

I make calls like this in update, and in touchesMoved. Thus this could mean hundreds of these calls, sometimes nested with groups of other actions.

Am I incurring significant overhead relative to directly setting the zRotation property?

Kelvin Lau
  • 6,373
  • 6
  • 34
  • 57

2 Answers2

2

You should not call a SKAction in the update method as it is called 60 times a second. Instead, use a event based trigger which in turn calls the SKAction. The touchesMoved is a good example of that. You can also use a completion method block to signal for a new SKAction upon completion of the current action.

sangony
  • 11,636
  • 4
  • 39
  • 55
2

Never use SKActions for real-time motion. Instead you should either set the zRotation directly or set the necessary angular velocity each frame. In your case the update method and touchesMoved method are both bad to use for SKActions because they can run 30-60 times a second.

SKActions do generate significant overhead. Here is a quote from Apple's documentation:

When You Shouldn’t Use Actions

Although actions are efficient, there is a cost to creating and executing them. If you are making changes to a node’s properties in every frame of animation and those changes need to be recomputed in each frame, you are better off making the changes to the node directly and not using actions to do so. For more information on where you might do this in your game, see Advanced Scene Processing.

Source

You can see an example of using real-time motion instead of SKActions in my answer here

Community
  • 1
  • 1
Epic Byte
  • 33,840
  • 12
  • 45
  • 93