Putting it all together

First, we learned how to use actions to move, scale, and rotate our sprites. Then, we explored animating through multiple frames, bringing our sprite to life. Let us now combine these techniques to fly our bee back and forth across the screen, flipping the texture at each turn.

Add this code at the bottom of the didMoveToView function, beneath the bee.runAction(beeAction) line:

// Set up new actions to move our bee back and forth: let pathLeft = SKAction.moveByX(-200, y: -10, duration: 2) let pathRight = SKAction.moveByX(200, y: 10, duration: 2) // These two scaleXTo actions flip the texture back and forth // We will use these to turn the bee to face left and right let flipTextureNegative = SKAction.scaleXTo(-1, duration: ...

Get Game Development with Swift 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.