This is just an INTRO to Cocos2D.\nI’m not going to cover *everything* that it’s capable of (Physics, Tilemaps, etc.), but enough to create something incredibly simple.\nThe goal is to just show how easy it is to get a BASIC 2D game up & running with the engine on iOS.\n
Open Source (Custom License)\n2D Engine (Using GL ES 1.1 / GL 1.5, 2.0 (in alpha) will be moving to GL ES 2.0\niOS/Mac OS X port of Python based engine (using Objective-C) (iOS ~2008, OSX more recently)\n- Follows its design styles, memory patterns (ie. lots of Autoreleased objects).\n\nLarge number of features:\n- Integrated Tilemap, Particle Engine, Menu System\n- Integrates with Box2D & Chipmunk for Physics (Optional)\n\nIncredibly popular engine.\n - A lot of good resources/tools out there (will cover at the end)\n - Easy to add additional functionality (is installed as src into project, and most other addons are done the same way.\n - Extensibility lead to alternate ‘distribution’ Kobold2D\n\n2500+ Games using it on the App Store (at last count).\n\n\n
A few examples out there (a random selection of games I have on my phone)\n\na) Commander Pixman\nb) Trainyard\nc) Infinity Field\nd) League of Evil\ne) Super Shots Golf\n
A few examples out there (a random selection of games I have on my phone)\n\na) Commander Pixman\nb) Trainyard\nc) Infinity Field\nd) League of Evil\ne) Super Shots Golf\n
A few examples out there (a random selection of games I have on my phone)\n\na) Commander Pixman\nb) Trainyard\nc) Infinity Field\nd) League of Evil\ne) Super Shots Golf\n
A few examples out there (a random selection of games I have on my phone)\n\na) Commander Pixman\nb) Trainyard\nc) Infinity Field\nd) League of Evil\ne) Super Shots Golf\n
A few examples out there (a random selection of games I have on my phone)\n\na) Commander Pixman\nb) Trainyard\nc) Infinity Field\nd) League of Evil\ne) Super Shots Golf\n
\n
- Visit the website (Link at the end regardless)\n- Download the package (.tar.gz)\n- Unpack, and run the install-templates.sh script.\n- This installs everything for both Xcode 3 (remember that?) and Xcode 4\n- Then you fire up Xcode, create a new project…\n
…BOOM!\n\nHere you get 3 default configurations. A plain Cocos2d project, a Cocos2d project linked to the Box2D physics library, or the Chipmunk physics library.\n\nPlus you also get the same configures applied to building OS X targets.\n\n(All of which are a tad beyond scope on this one).\n
\n
Basic Concept:\n- Graph of Nodes\n- Each graph starts off with a scene: This is just used to anchor everything else\n\nThe Director manages the overall flow of the game (much like UIApplication does for a UIKit app).\n\nThe Director can load or replace a scene, can also push & pop scenes (allowing you to create a pause screen or menu eg).\n
Layers separate out items on the scene.\nEnsures that as you manipulate items in the scene, that others can be left affected.\nExamples - your game’s UI. You don’t want this to move about as your player moves through the world.\n\n
Benefit of a giant node graph is parent/child relationships.\nCould have a RPG where you could attach armour/weapons depending on inventory.\n\n
- Direct support for Touch & Accelerometer Input\n- Includes handling for multitouch\n
- Custom Callbacks on your Layers\n- Allows for focused handling (a bit out of scope)\n- Lets you split touch tracking on different layers (ie. for UI & action)\n\n-\n
No. Gesture. Recognizer. Support.\n- There is an unofficial patch to add it, which I’ve not tried\n- \n
- Again, enabled on a per layer basis.\n- Nothing really special here\n- Need to manually track reference position (ie. Calibration UI - we don’t get anything special here).\n
- There’s no out of box handling for the gyro - unsure why though… just not there!\n- CoreMotion’s easy to set-up though - if you’re happy to keep to iOS 4+.\n- That being said, even with the Gyro you need to track reference points (plus deal with Gimbal Lock issues if you’re not careful).\n- CoreMotionTeapot code from WWDC2010 code is a great starting point for this.\n
\n
- C2D includes “CocosDenshion” - an engine handling both AVFoundation/AudioToolbox & OpenAL.\n- Also includes a SimpleAudioEngine wrapper around that - one line playback (or two with preloading) of music/sound effects\n\n- An alternative is ObjectAL - out of the box there’s a few benefits (easier to do some other things - looping sound effects).\n
Obtain the SharedAudioEngine instance (it’s exposed as a singleton!)\nThen you can preload/play/unload\n\nPreloading ensures the sound is ready to go (so no delay when required)\nUnloading helps to manage memory of course\nPlay performs a single shot.\n\nPlay has a more complex overload - can tweak parameters, allows you to get some dynamic audio in there\n
Obtain the SharedAudioEngine instance (it’s exposed as a singleton!)\nThen you can preload/play\n\nPreloading ensures the sound is ready to go (so no delay when required)\nPlay can play it once, or continually loop until stopped.\n
Time to show this in action.\nFire up the game (via the iPad or the simulator - NB: NO AUDIO ON SIM)\n\nBreak through the codebase.\n- Show how the scenes are set-up\n- Title:\n- How the menu is built & handled\n\n- Game:\n- Layers (background, HUD, gameplay)\n- Show touch input\n- Show audio playback\n\n- General\n- Show Fonts\n- Show Director & Transitions\n- Show Actions\n\n
Just an overview of what Cocos offers.\nI prefer it due to fitting somewhat in line with general iOS semantics.\nThere are other engines (Sparrow, Pixelwave, iTorque, even wrangling Unity into a 2D engine).\n\n
Cocos Homepage - here’s where you can get the source/package of the stable releases (as well as the possible 2.0 alphas & other builds).\n\nAlso has the documentation (including offline versions for Xcode) & some other tutorials (which might be out of date)\n\nAlso the link to the source for the demo game - should be ready to go & build with the latest iOS SDK (Built using the 5.0GM, needs 4.2 to run ‘cause I use lots of blocks!)\n
\n
These are the two major books on using Cocos2D. I prefer the first, but the second is about to get an updated edition covering iOS 5, UIKit, the Cocos3D library\n