Introduction

I have never tried creating a game before; it feels like magic to me. I know that games have an enormous amount of underlying layers of abstractions and tools such as game engines, rendering, and so on. I have always been eager to learn at least 1% of the game creation process. In this article, I’m going to explore step-by-step instructions for creating a game for the iOS platform using SpriteKit.

First Step

The first step is to create an Xcode project using the iOS game template and SpriteKit Game Technology.

Second Step

The second step is to add resources like images and sounds. You can find assets inside the Assets folder Download Project.

Third Step

The third step is to override the didMove(to:) method - it tells you when the scene is presented by a view. This method is similar to viewDidLoad for UIViewController. We will be implementing logic inside it.

override func didMove(to view: SKView) { }

Creating and Adding Starfield Background

The next step is to create and add a starfield using SKEmitterNode as a child to SKScene. After that, you will be able to see the starfield in the background.

self.starfield = SKEmitterNode(fileNamed: "Starfield")
starfield.position = CGPoint(x: self.frame.size.width / 2, y: self.frame.size.height)
starfield.advanceSimulationTime(10)

self.addChild(starfield)

starfield.zPosition = -1

Let’s Dive a Little Deeper

Custom Particles Creation

If you were wondering how to create custom particles similar to the starfield background, you need to:

  • Create a new SpriteKit Particle File:
  • Choose a particle template:
  • Select the created file -> Open the Inspectors side menu and configure it with settings that you like.
SKEmitterNode

Initialization of SKEmitterNode(fileNamed: "Starfield") helps create a starfield background.

SKEmitterNode is a node that automatically creates and renders small particle sprites. Particles are privately owned by SpriteKit—your game cannot access the generated sprites. For example, you cannot add physics shapes to particles. Emitter nodes are often used to create smoke, fire, sparks, and other particle effects.

advanceSimulationTime

advanceSimulationTime(10) - Advances the emitter particle simulation. In other words, you do not need to wait until the particles reach the bottom of the screen.

addChild

self.addChild(starfield) - Adds a node to the end of the receiver’s list of child nodes. After that, you will be able to see the starfield background.

zPosition

zPosition = -1 - Moves the starfield to the back of the screen.

Resources

Enormous appreciation for Brian Advent for his comprehensive video. Without it, I would still be surfing the internet and collecting pieces of the puzzle.

Download Materials

Download Project

Thank you for reading! 😊