Friday, May 25, 2012

Getting Started with Cocos2d


Cocos2D for iPhone is a great open source framework that makes it easy to make some very impressive 2d games with much less effort than having to know OpenGL directly or rely on a third party system that might have performance issues or be unnecessarily bloated.   From the official cocos2d for iphone website:
Cocos2D for iPhone is a framework for building 2D games, demos, and other graphical/interactive applications. It is based on the cocos2d design: it uses the same concepts, but instead of using python it uses Objective-C.”
Many of the most complex features are done for you, but like any open source software you can make changes as required.  I however, doubt you will need to do many modifications on your own given that it’s very easy to subclass and handle drawing yourself as you become more experienced.  Using Cocos2d is really one of the best ways to get your feet wet with OpenGL programming and learning Objective-C. HOWEVER, it is a programming language and that means you will need to understand the fundamental concepts of programming.

Cocos2d for iPhone is:
  • Easy to use: it uses a familiar API, and comes with lots of examples
  • Fast: it uses the OpenGL ES best practices and optimized data structures
  • Flexible: it is easy to extend, easy to integrate with 3rd party libraries
  • Free: is open source, compatible both with closed and open source games
  • Community supported: cocos2d has an active, big and friendly community (forumIRC)
  • AppStore approved: More than 1000 AppStore games already use it, including many best seller games.
cocos2d for iPhone supports: iPod TouchiPhone and iPad
Download the latest build at:
As of the writing of this – The latest stable build was 0.99.4 and the package runs about 30 megs with all sample code and libraries included
Because no one seems to read the readme files anymore until they get into trouble, I am listing some of the things to note that might otherwise be overlooked.
Build Requirements
——————
Mac OS X 10.5.3, Xcode 3.1, iPhone OS 2.0, Beta 8 release or later
Runtime Requirements
——————–
Mac OS X 10.5.3, iPhone OS 2.0, Beta 8 release or later
Files and Folders
—————–
* cocos2d/   <— core files and folders of cocos2d
* cocoslive/ <— high score client library
* CocosDenshion/  <— sound engine library
* tests/  <— tests, demo and template examples
* experimental/ <— experimental stuff
* external/ <— 3rd party libraries used by cocos2d or any other project.
* Chipmunk/:  physics library
* Box2d/: physics library
* TouchJSON/: JSON parser
* Tremor/: OGG audio decoder
Setup Script:
Ok now to the good stuff – one of the real nice items that has been included in the package is an install script that will populate your “user templates” in xcode with a few predefined ones for cocos2d.  This will save tons of time in the initial setup of cocos2d.
Run the ‘install-templates.sh’ script as root:
$ cd cocos2d-iphone
$ sudo ./install-templates.sh
OR with `-u` to install the templates in your user directory:
$ cd cocos2d-iphone
$ ./install-templates.sh -u
And then open XCode -> New Project -> User Templates -> cocos2d
That’s it for now – If you have any problems with the initial setup of cocos2d, either post it in our forums or use the “cocos2d for iphone” reference below to find a solution.  Hopefully that’s enough to get you started for now and we can begin diving into the code more directly!
References Link!
Main Cocos2d Websites:
Site with a few open source games (and the rest are some great open source projects) for the iphone
http://maniacdev.com/2010/06/35-open-source-iphone-app-store-apps-updated-with-10-new-apps/
Box2d: extending b2ContactFilter and b2ContactListener:
http://blog.xyris.ca/?tag=box2d
Box2d Reference and Tutorial (C++):
http://www.box2d.org/manual.html#_Toc258082967
Cocos2d iPhone Google Code Page:
http://code.google.com/p/cocos2d-iphone/
Using Chipmink ONLY for collision detection:
http://www.cocos2d-iphone.org/forum/topic/577
Chipmunk 5.0 New Collision Detection Function:
http://www.cocos2d-iphone.org/forum/topic/3996
Using CCCallFunc with parameters:
http://www.cocos2d-iphone.org/forum/topic/721
Overview of Cocos2d (a little old but still good):
http://lethain.com/entry/2008/oct/03/notes-on-cocos2d-iphone-development/
Objective-C Memory Management:
http://www.bit-101.com/blog/?p=2233

No comments:

Post a Comment