Chapter 5 - Getting bigger and better
The gist of this chapter will be to discuss the simple game project from the previous chapter. I threw everything into one class, clearly not what you want to do for bigger games. But getting from one-class to real code design is a big step which some hesitate to take. I’ll make that easier and discuss common issues and their solutions, such as what to seperate, what to subclass from and how you can have all the seperated objects communicate with each other and exchange information in various ways.
A big topic will of course be how to take advantage of cocos2d’s scene hierarchy and which pitfalls it may have when moving from a single-layer game to one which has multiple layers and even multiple scenes.
As for the chapter title I’m not so sure if that’ll be it. Maybe along the way while I’m writing I’ll change it. Suggestions welcome!
The chapter will be submitted on Friday, July 30th.
What’s your take on good cocos2d code structure?
Did you ever struggle with cocos2d design concepts? Or the cocos2d scene hierarchy? Or how to layout a scene and divide your game into logical parts? Tell me about it.
I know theses questions are somewhat generic to ask. It’s about the things that don’t feel right but there doesn’t seem to be a better, more obvious way. I think we all know some of those, if you do, be sure to tell me! Leave a comment or write me an email.
Summary of working on Chapter 4 - First simple game
The game I chose to make is called Doodle Drop and features dropping spiders and an accelerometer controlled alien trying to avoid the spiders. All in all it got divided into 8 concrete steps. Lots and lots of code comments, too.
It starts simple enough, adding resources to Xcode and adding sprites. It gets more gameplay-esque when the accelerometer-driven player controls got tweaked to provide acceleration and deceleration of the player object. In contrast, the spiders movements are driven only by actions.
I introduce you to two undocumented features of cocos2d, namely CCArray which is since v0.99.4 used to store all children of a node. The other are the CGPointExtension class which has all the functions normally provided by a physics engine, however not every game should link a physics engine just because one needs those math functions. That’s why CGPointExtension comes in handy.
With the ccpDistance method the collision checks are done. Simple radial collisions, and in debug mode the collision radii are drawn too.
In between the CCLabel for the score got replaced with a CCBitmapFontAtlas, because it killed the framerate. I shortly mentioned Hiero and how to use it in principle but for all the details there was no room. But while I was at it I created the Hiero Tutorial.
At the end of the project I added some polish which isn’t described in the book (too many details) but really adds to the game’s look and feel. The spiders drop, hang in there, then charge before dropping down, all done using actions. I’ve also added the thread they’re hanging from using ccDrawLine. And then there’s a game over label which shows even more action use.
One of the principles I followed is to stay away from fixed coordinates as much as possible. So the project, once finished, did run just fine on an iPad. Although the experience is a different one, there’s more spiders dropping and they drop faster but there’s also more safe space to maneuver to.
Oh and, the game art is all mine. Yes, I know … but Man-Spiders do have just six legs!
I’m pleased to announce that the Line-Drawing Game Starterkit is finally available for sale! It’s a source code project for anyone interested in developing a line-drawing game. The gameplay is modelled after the famous Flight Control game. The Starterkit works with the latest cocos2d v0.99.4 version and will at the very least receive compatibility upgrades for future cocos2d versions.
Hop on over to the product page to check out the feature list, the API documentation and a source code sample. You can also download the Starterkit App for iPhone from iTunes. The iPad Edition is still in approval.
Note: for the reminder of July 2010 you can get the Starterkit at an introductory price for only $179!
Positioning of the Starterkit
I’m sorry that you’ve had to wait one and a half months compared to the initially planned release date of June 1st. I double and triple checked every decision I made and you can see some of the results on the Starterkit product page.
I’ve also decided to increase the regular price from the initially intended $199 to $299 effective from August 1st, 2010. One of the reasons being that I initially planned to have multiple licenses including Indie and Commercial ones. I thought long and hard about positioning the Starterkit and eventually decided to sell only Site Licenses. For the individual developer it costs a bit more but for small and commercial teams it’s great news, and small teams and established, dedicated developers is who I am targeting. Those who really appreciate the value of commercial source code saving days and weeks of research and development, and all the trouble, sweat and pain associated with it. And I’m here to help if you have any questions regarding the Starterkit’s source code.
I don’t have plans to make another Starterkit and in all likelihood it will remain the only commercial cocos2d-related product for the remainder of this year.
Book Chapter about Line-Drawing Games
For those who are disappointed about the new price, either grab the Starterkit before August 1st or wait until December for the Learn iPhone and iPad Cocos2D Game Development book I’m writing. It will contain a chapter covering some of the basic aspects of a line-drawing game but without the finer details and complex interactions conveyed in the Starterkit. It’ll be Chapter 12 so in about 8 weeks (Mid-September) I’ll mention it in my weekly book chapter posts.
Closed Sales Period, Summary of
And here’s for transparency: exactly 10 days ago I informed the 668 subscribers of my Newsletter of the closed sales period. The password-protected Starterkit product page received just over 200 unique visitors. During the last 10 days I made 9 sales amounting to about $1,530 with Plimus’ 5% fee already deducted but obviously before tax. All sales were made within the first 4 days after I sent the Newsletter and for the last 6 days sales were absolutely zero. Although I’ve been in contact with several interested parties who didn’t want to or simply couldn’t buy it right now for various reasons. If you’re one of them: you’ll get it for $179 no matter when you make the purchase, just contact me beforehand.
Right now I’m curious to see how sales will be now that the Starterkit is publicly available.
Starterkit Promotion
I’d appreciate if you would tweet and re-tweet this post and mention the Starterkit to all fellow cocos2d-sians! If you would even go so far as writing a serious and honest review on your blog, please get in touch with me.
Just don’t test the waters by mentioning the Starterkit in the cocos2d community forum.
Stance Lance
I wish Ricardo had taken the time to be considerate and then talked to me instead of running off making an assumptive, excessive, and for the most part irrelevant (off-topic) stance post which only served to cause a big commotion among his community while allowing his forum rule “Treat people with respect.” to become a farce.
In Conclusion
In hindsight I’m glad that the whole thing got me thinking in so many new directions. Most importantly it got me in contact with a lot of developers who consciously don’t post on the cocos2d forum. To get those encouraging words and positive feedback and gaining interesting insights from other developer’s perspectives - especially those who tag along silently - really helped me understand the cocos2d development community better. Thank you, you know who you are!
The whole shebang also served as a great motivational factor to pour my everything into the cocos2d book, which came at just the right time to let off steam in just the right way. I’m writing it to be the cocos2d documentation it deserves and the one I always wished it had. I can’t even begin to describe how satisfying it feels to write this book. So much in fact that it hurts to stop writing every time I reach the 27 pages each chapter is expected to have.
Line-Drawing Game Starterkit
Get a head-start for your Line-Drawing game and save days if not weeks of your time! You’ll get gameplay code modelled after the extremely popular Flight Control game. You’ll learn how to draw lines, detect touches on objects, have objects follow a path - and much, much more! Written by a professional game developer and game industry veteran (me) the source code is annotated with lots of comments explaining my rationale and written with readability in mind.
Contains both iPhone & iPad versions!
The Starterkit compiles to both iPhone and iPad devices natively using the same code. If the iPad Target is selected hi-res images will be used. Image selection is done automatically by loading those images whose filenames have the “-ipad” suffix. Game parameters can be tweaked individually per device using
precompiler directives.
All artwork provided by Arezou Ipakchi Design.
What others are saying:
“Code is quite clearly written and decently documented [...] definitely a fine investment.”
From: Commercial cocos2d Code review from Alex Curylo.
“It was an awesome moment when I found the source for a line draw game of this caliber.”
-Franklin Lyons, SpinFall
“Especially the path and movement system is saving me lots of headaches.”
-Martin Hoffmann
Games made with this Starterkit:
Launch Control
![]() |
![]() |
![]() |
Ferries HD
Feature List:
- clearly seperated and well-structured GameScene code design with a minimum of dependencies
- easy to add new objects and extend object parameters
- assertive coding style to help catch coding errors early on
- touch object & draw a path for it (whether it’s already following a path or not)
- path drawing ends when path is drawn over appropriate target location (eg airstrip for airplanes, respecting angle of approach)
- path drawing ends when arbitrary point limit is exceeded (to avoid slowdowns)
- path is drawn when dragged with thick transparent line style like Harbor Master, without glitches
- path is split into equal length pieces no matter how quickly user moves finger
- objects spawn outside screen, locations can be re-defined and extended
- objects display incoming warning marker at screen border
- objects display collision warning when any two of them are getting too close
- objects follow path to end - then fade out and increase score or continue moving
- objects always rotate in movement direction
- objects bounce back at screen borders
- motivational Labels for successful landings, precached
- Score and HighScore Labels
- HighScore saved to disk between play sessions
- supports both Landscape orientations with autoflip
- loads correct resource files depending on Target (iPhone or iPad)
- proper Pause handling for incoming calls, SMS
- Many generally useful Math Helper functions included
- Lots of comments explaining rationale and giving tips for improvement
- Fully documented
- Uses the professional Xcode Project from my Tutorial (Feature List)
- includes both iPhone/iPod Touch and iPad versions using seperate Targets, same codebase
- uses and includes cocos2d v1.0.1
- compatible with iOS 3.x, 4.x and 5.x
- compatible with Xcode 3.2 and Xcode 4.x
- easy setup, just unzip and use - no Xcode project setup required
Questions? Need Help?
Go to the support forum for the Line-Drawing Game Starterkit on Cocos2D Central.
Note: the Line-Drawing Starterkit support forum is a public forum. In case you need to post sections of code from the starterkit I’d appreciate it if you kept them short and to the point.
Legal Disclaimer
Cocos2D is a registered trademark of Ricardo Quesada. Steffen Itterheim, the Learn & Master Cocos2D website and the Line-Drawing Game Starterkit are neither affiliated with nor endorsed by Zynga or Ricardo Quesada.
Try Before Buy!
Buy Now!Site License! Unlimited Apps!Royalty Free! No Attribution!60 day money-back guarantee!(
|
License Agreement
Copyright
Purchase grants you the License to use and modify the source code and assets under the following Terms and Conditions:
You are not allowed to make the source code publicly available. You are not allowed to give or sell the source code to others, modified or not. Licenses are not transferable.
All Licenses are royalty free. You can make as many free or commercial Apps using the source code as you want. You may re-use any existing assets in your App.
If you do contract work and have or want to give the Starterkit source code to your client, your client needs to purchase a Site License as well.
Site License
Each purchase grants you a Site License. The Site license grants you the use of the Starterkit without restrictions at one site.
A site is an office, building or living space rented or owned by the company or individual making the purchase. It allows anyone working on site to use and modify the Starterkit source code.
Large companies operating at several sites need to purchase a site license for each individual location if the Starterkit is to be used at multiple locations. Contact me if you’re such a corporation and you prefer a flat fee license with your own license text to go along with it.
Support
Updates to the Starterkit are done on an as needed basis. I will also keep it up to date and running with the latest stable releases of cocos2d. Updates are distributed via a download link sent to the email address you used for your order. If your email address ever changes please contact me, ideally you should forward me your order confirmation in that case to speed up the change.
Source Code not covered by this License
The licensed Source Code project contains files which are available for free and are governed by different licenses. The Terms & Conditions outlined here do not apply to source code files which do not contain the Copyright notice “Copyright (year) Steffen Itterheim. All rights reserved.”.
Disclaimer
THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Questions? Contact me!
If you have any questions or if you require specific License texts before making a purchase, please contact me.
I’m sure you’ll want to know which iPhone games i’ve worked on. I’ll keep updating this post. Latest releases are on top.
Undisclosed Project
More info soon …
Black Hole
Created for Fun Armada, our iPhone game company startup. Published by ClickGamer.
![]() |
![]() |
MIX-MAX iPad Edition
Contract work for Ravensburger Digital
![]() |
![]() |
MIX-MAX
Contract work for Ravensburger Digital
![]() |
51 Japanese Characters
Pro Bono project for Peter Machat.
![]() |
![]() |
Steffens Complete Gameography
You can view my complete Gameography which includes the PC and Handheld titles i’ve worked on at my professional job application website www.gametooldeveloper.com.