16 June 2010

Introducing New Cocos2D Sample Game: Tom the Turret

This turret has gained self awareness!

This turret has gained self awareness!

This is just a quite note to let you guys know about a new Cocos2D example game out there for you guys to check out – and it comes with the latest beta version of Cocos2D!

The game is called Tom the Turret and is about a turret who gains self-awareness in an apocolyptic future. It’s a shooter in the style of the How To Make A Simple iPhone Game With Cocos2D Tutorial, and features multiple levels and endings!

Steve Oldmeadow and I wrote this project to demonstrate how to use the CocosDenshion sound library, and to give an example of how to put together some of the concepts from the tutorials on this site into a complete game. The art was made by my lovely wife, as usual!

What Does it Include?

Tom the Turret demonstrates how to do the following in a simple game with Cocos2D:

  • How to use the CocosDenshion sound engine effectively
  • How to have multiple scenes (loading scene, main menu, story scene, action scene)
  • How to have multiple levels and monsters
  • How to shoot in 360°
  • How to draw health bars
  • How to use Spritesheets and animations (I’ll be posting a tutorial on this soon btw!)
  • And much more!

So be sure to check it out – and choose your favorite ending!

Tom the Turret Screenshot: Level 2

How Do I Get It?

Simply download a copy of Cocos2D 0.99.4-beta that was recently released by riq.

Open up the cocos2d-iphone.xcodeproj, set your Active Target and Active Executable to “CocosDenshion – Tom the Turret”, compile, run, and enjoy!

Questions, Comments?

After you check out the project, if you have any questions or would like anything explained, feel free to post below!

Steve Oldmeadow may be writing some notes about the audio implementation in this game on the Cocos2D forums and the Cocos2D wiki, so stay tuned there as well!

Category: iPhone

Tags: , , ,

33 Comments

  1. Jason (12 comments) says:

    Fantastic! Thanks Ray.

  2. Jason (12 comments) says:

    Man, that is a challenging game! lol

  3. Chris Kimpton (1 comments) says:

    Looks great, thanks.

    I am trying to dig into it to find out about the animations (cant wait for your tutorial). It seems to reference some images I cant find, like Tom.png.

    Is there somewhere mapping a “virtual” image to the “sprites.png” sheet of images?

    Thanks,
    Chris

  4. Ray Wenderlich (492 comments) says:

    @Jason: Haha yeah it is pretty tough, I have a tendency of making difficult games and then having to ramp back the difficulty for release (which I never did here) ;]

    @Chris: Ah yes, the images are all stored in the sprites.png as a sprite sheet, and the mapping of where each image is located in the spritesheet is in sprites.plist. This is a file auto-generated by the Zwoptex tool.

    I’ll be discussing this in the upcoming animation post, but in the meantime I also have a discussion of it in this tutorial: How To Use Box2D For Just Collision Detection with Cocos2D.

  5. Jason (12 comments) says:

    Ray, good thing I’ve got access to the source code! I think I will tone it down a bit for myself. I’m just not quick enough! lol :-)

  6. Nirbhay (5 comments) says:

    amazing. Thanks.
    This would be a great help.

  7. vahala2009 (1 comments) says:

    Great sample! help us lots on making a real game!
    I wander why you draw the health bar by OpenGL directly. why not use cocos2d-iphone stander ways like a separate CCSprite which got 3 CCSprite for a Ids: long green one, middle yellow one and a short red one.
    You know the complex of OpenGL really stop us from quick advance in game development through a lot of books there.

  8. Ray Wenderlich (492 comments) says:

    @Jason: Lol that is the nice part of having the source! :]

    @vahala2009: Yeah that would have worked too (maybe even looked better!)

  9. Maniacdev (5 comments) says:

    Was just checking this out with the Latest update of Cocos, looks great, but I had to move the TomTheTurretAppDelegate files around to get it to work.

  10. Ronald (1 comments) says:

    Hi Ray, Big thanks! Now the turret shoot as i tap on the screen. Do you have a tutorial how to use a joystick with cocos2d? i want to try it on the turret. Thanks

  11. Maniacdev (5 comments) says:

    NM my previous comment.. it looks like the unarchiver i was using for some reason messed up some file names – or there was a stealth update.

  12. fazalyazdan (2 comments) says:

    dear sir
    thanks its a very good example its very great for learning i have learn a lot from this. And the graphics are also very good .

    Thanks

  13. Ray Wenderlich (492 comments) says:

    @Maniacdev: Odd, not sure what happened there. I pulled down the latest release and it seems to work OK, maybe something wonky happened in some release?

    @Ronald: I don’t have a tutorial on how to use a joystick with cocos2D, however sounds like a good idea, added it to the idea list! In the meantime, I came across a nice joystick library a while back written by “sneakiness” that looks like it might be helpful:

    http://github.com/sneakyness/SneakyInput

    @fazalyazdan: Thanks, I told my wife you liked the graphics and she was very happy! :]

  14. fazalyazdan (2 comments) says:

    dear sir
    please post a simple game on chipmunk in cocos2d because i am new to this and don’t know about how to use chipmunk. i had learn t a lot from your games so please do it must i will be waiting for your response . Also explain the function etc in chipmunk means how they are work.

  15. Alx (1 comments) says:

    hello, great tutorial however i am trying to implement a pause game button in this tutorial and i am unable to add such a code. im a beginner and would really appreciate some a sample code to help me out. thanks

  16. Ray Wenderlich (492 comments) says:

    @fazalyazdan: Haven’t used Chipmunk myself yet, but if/when I do I’ll probably post a tut!

    @Alx: Cocos2D makes this pretty easy, there are methods in CCDirector called pause and resume that you can use.

  17. Dell (6 comments) says:

    Ray, this looks great… but how to pull this into its own project. I can get it to build and run no problem from the default install and see the .h and .m files for the project but I want to create my own directory as a separate project for this. Can you point us in the right direction so we can dive into the code pre-tutorial?

    Thanks Dell!

  18. Jim Murff (17 comments) says:

    Ray;
    Did you have to do anything special to use the
    #import “CDXPropertyModifierAction.h”.
    I pulled out your example to play with and I am linking against a central cocos2d (instead of a copy for every project).

    Everything is fine but the linking using this header. Looks like CDXPropertyModifierAction.m is not getting into the libcocosdenshion.a library. Did you have to set a flag to add this as an extra?
    -Jim

  19. Ray Wenderlich (492 comments) says:

    @Dell: Sure, here’s how to pull it into your own project:

    1) Create a new cocos2d application with the cocos2d template (I named mine TomTest)
    2) Copy everything from cocos2d-iphone-xxx\CocosDenshion\TestsAndDemos\TomTheTurret to your app’s directory, overwriting all (i.e. the TomTest dir)
    3) Also copy the CDXPropertyModifierAction.h/.m from cocos2d-iphone-xxx\CocosDenshion\CocosDenshionExtras
    4) Add all the files (*.m, *.h, *.png, *.caf, *.wav, etc.) you copied over to your project
    5) My fps_images.png got lost when I tried this so I needed to re-add it.

    Then compile and run, and it should work!

    Or you can skip all of the above and download the standalone version of Tom the Turret that I just built :]

    @Jim: Hopefully the above should answer your question about CDXPropertyModifierAction as well.

  20. George (1 comments) says:

    Hey Ray, huge fan of all your tutorials. They’ve made life much easier for a complete newbie such as myself when it comes to learning objective-c as well as cocos2d. I have a question on your Tom the Turret example and I may be alone here because I haven’t seen anyone else with this issue. When I go to build the file using the default cocos2d template with the active target and active executable I get an error relating to a part of cocos2d saying something about “property with ‘retain’ attribute must be of object type”

    Okay, fine, so I try to do what you posted earlier, just copy over all the files into a new blank file. When I do that, I receive only 1 error which says
    Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
    I’m sure I’m missing something extremely obvious here. Any input from anyone would be great. I’m using xcode 3.2.3 with cocos2d 0.99.4-rc3. Thanks again!

  21. CyberGreg (2 comments) says:

    Ray – yet again your sample application is simply fantastic! Thank-you for taking the time to make the demo so complete.

    to Ray>
    :-]

  22. Ray Wenderlich (492 comments) says:

    @George: Hm not sure without seeing the project, but why not just download the standalone version I’ve already put together above?

    @CyberGreg: Thanks so much, glad you like it! :]

  23. Darrell Johnson (1 comments) says:

    I have a question.. I have a fairly recent version of cocos 2d.. Do i still have to download that beta to complete this tutorial? also.. what happens to my current version of cocos 2d?

  24. Ray Wenderlich (492 comments) says:

    @Darrell: If you have any version of Cocos2D at or above the version mentioned here, Tom the Turret should be included.

  25. DcGoD (1 comments) says:

    As always…. Great tutorial!!! You truly have made life easier for MANY of us…

    Do you have any plans to provide a solution to making the “Tom the Turret” game using a viewcontroller in order to properly implement iAD’s?

    I figured I would ask here first since I love your techniques to many of these solutions! Once again, THANK YOU!

  26. Jim Murff (17 comments) says:

    @DcGoD
    Create a view controller yourself and position it. Add to your view as a subview. Hide it and show.
    Here is a sample of what I used.

    adController = [[UIViewController alloc] init];

    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier480x32];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;
    adView.delegate = self;

    // Re Position the the view
    CGAffineTransform transform = CGAffineTransformMakeTranslation(-224, 206);
    transform = CGAffineTransformRotate(transform, CC_DEGREES_TO_RADIANS(90) );
    adView.transform = transform;

    // Set as invisible until the iAd is loaded
    [adView setHidden:YES];

    [adController.view addSubview:adView];

    [[[CCDirector sharedDirector] openGLView] addSubview:adController.view];
    inStage = YES;
    -Jim

  27. Nadeem Yasin (2 comments) says:

    Hi Ray..!
    Ur all toturials are very nice..
    i would like to ask u about one more toturial..
    can u plz make toturial in which multiple animations are being done with spritesheets using plist and frames..
    i m making a game in which i need to add multiple animations but whenever i added new animation, i have to load its plist, its png, make its frames which ultimately take 8mb of space and when i added some more animations memory is increased with same ratio..
    the game run on simulator but crashes immediately after adding two animations on device..
    if u have any solution in ur mind then plz do let me know, there are about 20 frames in each animation and i need to add almost 50 such animations..
    waiting for ur reply…

  28. Ray Wenderlich (492 comments) says:

    @Jim: Thakns so much for helping out @DcGoD!

    @Nadeem: I’m not sure if I’ll write a tutorial on that as it’s quite specific… however one thing you may want to consider is using the same sprite sheet for multiple animations, the less sprite sheets you have to load the better!

  29. Jess (1 comments) says:

    Ray, as an add on to Nadeem’s question, if I WERE to implement a Sprite sheet with multiple character animations, (i.e. several animations while jumping on the same sprite sheet as the character simply walking around) how would I need to do this? Could you make a tutorial dealing with more advanced sprite animations where a character has multiple kinds of animation on the same sheet, triggered by different commands? Even a suggestion in the right direction would be amazing.

    Your tutorials have really been fantastic. Never though I’d be able to do some of this stuff, let alone understand it!

  30. Jim P. (14 comments) says:

    I have one problem: I get an error that says “error: There is no SDK with the name or path ‘iphoneos3.1′”
    I have a feeling that I’m missing something blatantly obvious, but can I have some help?

  31. Ray Wenderlich (492 comments) says:

    @Jess: For that, just add all of your frames into the same sprite sheet (even if they’re from different animations) and then create the list of sprite frame names for each (like in step 3 of the animation tutorial), but usually you’ll want to put in the names of the sprite frames manually rather than looping through with a naming convention like we did there.

    @Jim: Yeah a lot of tutorials on this site were developed before iOS4 came out. Luckily this is easy to fix and the tutorials will still run – just go to Project Settings, and change the Base SDK to “iPhone Device 4.0″.

    For Cocos2D projects, you might have to Targets, and go to Target Settings for each project and change the Base SDK to “iPhone Device 4.0″ too if you still have troubles compiling.

  32. riash (1 comments) says:

    hi Ray,
    you are giving a nice tutorial to the beginner in cocos2d. i also like your way things..and i had one doubt on creating EXIT button on Menu in cocos2d game. i add the appDelegate.m to the EXIT button control .is it right way to do that or not ?

Leave a Comment

I'd love to hear your thoughts!

Tip: Want a cool picture next to your comment? Create a Gravatar!