So the following is my version of a really simple yet functional space shooter that later can be evolved into something really special. This first step is just creating the new project in Xcode and adding some code, along with using SpriteKit's particle effects to create a moving star field to simulate space ship motion.
Type in your space shooter name and of course select SpriteKit and Swift as the language.
On the next screen select where you would like to save your project and click Create.
After this steps you have a standard SpriteKit project which you can click Run and displays a gray scene with the words "Hello, World!".
So now to turn this into a star field with a ship.
Next you want to click on File \ New \ File...
On the screen Select Resource under iOS then select SpriteKit Particle File:
Next select Snow.

Next type in "StarField" as a name and click Create.
On your Navigator select the StarField.sks file.
In the StarField.sks file you need to change your emitter settings to match these.
- Particle: 12
- Lifetime: 20
- Position Range: X: 420 Y: 5
- Angle: 270
- Speed: Start: 80 Range: 120
- Alpha: Start:1 Range: 0.5
- Scale: Start: 0.04 Range: 0.01
Click anywhere in the black space and you will see the particle effect at work, these settings can be tweaked for a better effect if you want to, these are just baseline settings for a working star field.
Next you need to add the following code to your didMoveToView(view: SKView) method on your GameScene.swift file.
This code handles the following:
- Sets scene background color to black.
- Creates SKEmitterNode using the StarField.sks file, sets nodes position and zPosition and it's important to call advanceSimulationTime this makes sure you have stars when the scene shows up.
- Create the starship SKSpriteNode set it's scale and position.
- Add both nodes to the scene as children.
Now your GameScene.swift file should look like this.
You will notice that I deleted the code that displays the "Hello, World" message since its not needed. That is all for Part #1.
Now just Build and Run | ![]() |
the project. |
Your scene should look like this.

No comments:
Post a Comment