Animation—movement, scaling, and rotation

Before we dive back in to sprite theory, we should have some fun with our blue square. SpriteKit uses action objects to move sprites around the screen. Consider this example: if our goal is to move the square across the screen, we must first create a new action object to describe the animation. Then, we instruct our sprite node to execute the action. I will illustrate this concept with many examples in the chapter. For now, add this code in the didMove function, below the self.addChild(mySprite) line:

// Create a new constant for our action instance // Use the move action to provide a goal position for a node // SpriteKit will tween to the new position over the course of the // duration, in this case 5 ...

Get Swift Game Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.