April 2021
Beginner to intermediate
506 pages
11h 57m
English
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 |
| | |
| |
Read now
Unlock full access