How To Make a Game Like Space Invaders with Sprite Kit Tutorial: Part 2
Learn how to make a game like Space Invaders in this 2-part Sprite Kit tutorial! By .
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
How To Make a Game Like Space Invaders with Sprite Kit Tutorial: Part 2
45 mins
- Making Your Ship Fire its Laser Cannon
- Making Invaders Attack
- Detecting When Bullets Hit Their Target
- Implementing the Physics Contact Delegate Methods
- Updating Your Heads Up Display (HUD)
- Polishing Your Invader and Ship Images
- Implementing the End Game
- One Last Thing: Polish and Fidelity
- Where to Go From Here?
Where to Go From Here?
Here is the final example project from this Sprite Kit tutorial.
I encourage you to experiment with your SKInvaders game. Play with it, tweak it and see what you can do! Breaking your code, fixing it, then finally seeing an awesome new feature come to life is one of the many thrills of game development.
If you want a few ideas for how to tweak your game, here are some:
Add a victory or defeat message to your GameOverScene
Hint: Add a property to GameOverScene
that stores a message. Think about how to pass/set that property to the scene and how you would display it on-screen.
Add a title scene to your game
Hint: Add another SKScene
subclass (call it TitleScene
) that is displayed first by your GameViewController
. Tapping this scene should transition in your existing GameScene
.
Add a streak bonus when your ship hits invaders with three bullets in a row
Hint: Add a property to your GameScene
to track hits vs misses: increment it for hits, reset to zero for misses. When the player gets three consecutive hits, show a special "STREAK!" animation and play a special sound.
Animate invaders when hit by your bullets
Hint: Take a look at handleContact:
and think about how you could use a sequence of SKAction
actions to animate the invader that was hit. How might this complicate your game state? Would you need to mark these invaders as "dead" so that they would no longer be considered for future contacts or scoring while they were doing their "death animation", but not yet removed from the scene?
Add a "boss" invader that only moves horizontally across the top of the screen
Hint: Add new constants for this invader's name and category. Use a pixel art tool such as Pixen to draw your own "Boss Invader". Make him mean! Think about where you need to add code to manage this new invader by looking at existing code that adds existing invaders and go from there.
Get rid of the nodes and FPS debug info in the scene
Hint: Think about where and when the GameScene
was created and initialized.
Add a "player lives" feature instead of health
Hint: Currently, your game shows ship health. Instead, make the player lose a "life" each time their ship gets hit. End your game when they have no ships remaining. How will you show player lives on the screen?
Add a computer-generated voiceover to your game
Hint: Use a new feature in iOS 7 that makes your iPhone utter any NSString
that you give it.
Add a High Score List
Hint: Keep track of player scores. Show players the high score list after each game. If you want to personalize your game further, allow them to enter their initials with each score. Do this locally without Game Center.
Add defense shields between your ship and the invaders
Hint: In the original game, there were "defensive shields" above the player's ship that could absorb invader bullets. Each bullet that hit the shield would destroy part of the shield. As enough bullet hit a shield in the same area, channels would be carved through it that allowed bullets to pass through unhindered. The shields were evenly-spaced with gaps between them. The player could hide his or her ship underneath these shields.
Through this tutorial series you learned some new tricks about Sprite Kit by building a very cool classic game along the way. If you want to learn how to build more fun games like this, check out our brand new book iOS Games by Tutorials, where you'll learn how to make five complete games from scratch!
Enjoy playing your new game; I look forward to hearing from you with comments below or questions in the forums!