Cocos2D Tutorial for iOS: How To Make A Space Shooter iPhone Game

A Cocos2D tutorial for iOS that will teach you how to make a space shooter iPhone game. By Ray Wenderlich.

Leave a rating/review
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Gratuitous Music and Sound Effects

As you know, I can't leave you guys without some awesome sound effects and music to add in!

You've already added the sounds to your project, so just add a bit of code to play them in HelloWorldLayer.m:

// Add to top of file
#import "SimpleAudioEngine.h"

// Add to bottom of init
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"SpaceGame.caf" loop:YES];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"explosion_large.caf"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"laser_ship.caf"];

// Add inside BOTH CGRectIntersectsRect tests
[[SimpleAudioEngine sharedEngine] playEffect:@"explosion_large.caf"];

// Add inside ccTouchBegan
[[SimpleAudioEngine sharedEngine] playEffect:@"laser_ship.caf"];

And that's it - congratulations, you've made a complete space game for the iPhone from scratch!

You Win!

Want More?

I had a lot of fun working on this Cocos2D tutorial, so I actually spent a bit more time to polish this up and add some cool new features. Check out the following video to see what I mean:

I'm planning on making this (or something like it) into an actual iPhone game at some point, because I think the core concept is pretty fun.

But I was wondering if maybe you guys might also like me to turn this into a "Space Game Starter Kit" for sale on this site?

The starter kit would include the source code for the game in the video, plus a Cocos2D tutorial that shows how to make it from scratch, with the following features and instructions:

  • Using Box2D for Collision Detection
  • Using Physics Editor to define shapes
  • Resizing Box2D shapes based on Cocos2D sprite scaling
  • Detecting Box2D collision points
  • Playing animations for the ship and efficient preloading
  • Creating the alien ship and movement
  • Having enemies with various amounts of health
  • Shaking the screen
  • Adding Retina-display graphics
  • Making it a Universal App for iPhone + iPad
  • Creating powerups
  • Creating the cool zoom effect

But before I decide to do this, I want to make sure this is something you guys want. If not I won't mind, I have plenty of other stuff to work on lol!

So I'd really appreciate it if you could let me know if you'd like this (or not) with the following poll:

UPDATE: Thank you to everyone who voted! I removed the poll, because I got enough feedback, and by an overwhelming response you guys said you wanted it!

You guys asked for it, you got it! The Space Game Starter Kit is now complete, and available on the new raywenderlich.com store!

Where To Go From Here?

Here is the sample project with all of the code from the above tutorial.

And that concludes the How To Make A Space Shooter iPhone Game tutorial! If you want to learn more about Cocos2D, there are a bunch of other cocos2D tutorials on this site you can check out!

Thank you to @whereswayne from the forums for suggesting this idea! If you have an idea, feel free to suggest one yourself!

I know I still owe you guys a tutorial about OpenGL from a few weeks back, I'm still working on that LOL. It's quite a big subject!

Please join in the forum discussion below if you have any questions or comments!