Kodeco Forums

How To Make a Game Like Space Invaders with Sprite Kit and Swift Tutorial: Part 1

Learn how to make a game like Space Invaders using Apple's built-in 2D game framework: Sprite Kit!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1167-how-to-make-a-game-like-space-invaders-with-spritekit-and-swift-part-1

Hello, when I downloaded this tutorial on Xcode, it didnā€™t build. Instead, it gave me six errors. I donā€™t know if that is because I didnā€™t put the code in, however, when I tried to simulate the Gamescene.swift, it opened up an iphone screen instead without the opening screen as shown. If you could please help, I would appreciate it. Thank you.

Hi @navytrident933, Iā€™d love to help you get this working. What version of Xcode are you using? This tutorial has been updated for Xcode 7.3. Also what are the errors you are getting?

The Xcode version I am using is version 7.1. I just realized that myself and I am updating it right now. I think that might have been the reason as to why I was getting the errors. I didnā€™t realize it had an update. Thank you for letting me know. The errors I was getting were in the gamescene.swift file and they were syntax errors such as missing argument in parameter and the expected ā€˜,ā€™ separator error. Also the expected expression in list of expressions.

Okay, getting Xcode updated to 7.3 should solve this then. Let me know if it works after the update if not Iā€™ll see how else I can help you get this working. :]

Great tutorial! Small bug in the text: ā€œNow replace the println statement in processUserMotionForUpdate (right after comment // 4) with the following:ā€ should read ā€œNow replace the print statement in processUserMotionForUpdate (right after comment // 4) with the following:ā€.

As an aside, I like that Swift ditched strangely non-camelCase println with print. I suspect that println reflects Java influence.

Great tutorial. Has someone an idea for realizing the invader movement sound like in the original game?

Shouldnā€™t

   // 4
    for _ in 1..<kInvaderRowCount {
      // 5

Actually be referring to ā€˜kInvaderColCountā€™ ?

Since both the row and the column counts are identical, the result is the same in this case, but it would have made the logic of placing the sprites on the grid easier to understand for me.

1 Like

Good catch! I updated the tutorial so itā€™s not confusing for others in the future.

Minor syntax change:

Add the following code to createContent() right before the setupInvaders() line:
physicsBody = SKPhysicsBody(edgeLoopFromRect: frame)
The new code adds the physics body to your scene.

XCode 8.2.1 helpfully informed me that the new syntax is:

physicsBody = SKPhysicsBody(edgeLoopFrom: frame)

This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]