Load the Textures

Remember, a texture is nothing more than an image, or a visual representation for your sprite. To animate a sprite in SpriteKit, you can load an array of textures and cycle through them. Given this is something you’ll do a lot, it makes sense to use an extension[24] to load the textures.

Extensions, which are common to many programming languages, are a great way to reuse code, keep things organized, and extend the functionality of an existing class. To keep your code further organized, you’ll put the extensions into a separate file.

Create another new file (N) using the iOS Swift File template. Name the file SpriteKitHelper.swift and replace its contents with the following:

 import​ ​Foundation
 import​ ​SpriteKit
 

Get Apple Game Frameworks and Technologies 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.