How To Make A Simple iPhone Game with Cocos2D 3.0 Tutorial
Let there be ninjas! In this Cocos2D 3.0 tutorial, you’ll learn how to make a simple iPhone game, even if you’re a complete beginner. By Martin Walsh.
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 Simple iPhone Game with Cocos2D 3.0 Tutorial
30 mins
Finishing Touches
You’re pretty close now to having an extremely simple game now. But (Pew-Pew!), a bit of sound would be nice right about now.
Cocos2D uses the OpenAL sound library for sound support. No need to include any headers manually, it’s all good to go.
History Lesson: For the Cocos2D historians out there wondering what happened to SimpleAudioEngine, that sound library has now been superseded by Open AL.
History Lesson: For the Cocos2D historians out there wondering what happened to SimpleAudioEngine, that sound library has now been superseded by Open AL.
Playing a SFX is really easy, time to add a SFX every time the ninja throws his shuriken. The sound may not be a 100% accurate representation of a ninja throwing a shuriken :-)
Add the following to the end of your projectile creating touchBegan:
method.
[[OALSimpleAudio sharedInstance] playEffect:@"pew-pew-lei.caf"];
Time to add a little mood music, add this line to init
, right after setting userInteractionEnabled
to YES
:
[[OALSimpleAudio sharedInstance] playBg:@"background-music-aac.caf" loop:YES];
As a final step, comment out this line in init
to turn off debug drawing:
_physicsWorld.debugDraw = YES;
Build and run, pew-pew. You now have sound, how easy was that?
Where To Go From Here?
And that’s a wrap! Here’s the full code for the Cocos2D 3.0 game that you have developed thus far.
You have covered a lot of ground in this Cocos2D 3.0 tutorial, introducing you to the key areas of Cocos2D. From small beginnings come great things, so why not take things a bit further and improve upon the project?
Have a look at the code in the IntroScene you will see how to create a label. Why not try adding a counter to your game every time you destroy a monster?
What should happen when a monster collides with the ninja?
Want to try some more advanced animation, In Xcode Open Help\Documentation and API References and search for CCAction you will get a list of all the actions available that you can apply to any of your game character objects.
I’ve never seen a shuriken that didn’t spin, how about a little rotation (I’m sure we’ve seen an example of that earlier in this tutorial). Hint: You can use runAction
more than once on a node. It doesn’t have to be in a sequence.
-
Have a look at the code in the IntroScene you will see how to create a label. Why not try adding a counter to your game every time you destroy a monster?
-
What should happen when a monster collides with the ninja?
-
Want to try some more advanced animation, In Xcode Open Help\Documentation and API References and search for CCAction you will get a list of all the actions available that you can apply to any of your game character objects.
-
I’ve never seen a shuriken that didn’t spin, how about a little rotation (I’m sure we’ve seen an example of that earlier in this tutorial). Hint: You can use
runAction
more than once on a node. It doesn’t have to be in a sequence.
If you want to learn more about Cocos2D, the official Cocos2D forum is a friendly place to ask questions and learn from years of experience. My username is @cocojoe feel free to come in and say hi.
If you have any questions or comments about this tutorial, please join the discussion below!