Cocos2D: An introductionRob Caporetto (@rob_caporetto)www.rob-caporetto.com
Caveats
What is Cocos2D?
Getting Up & Running
Installing Visit the Cocos Page & download Run the installer to install the Xcode Templates
Installing Visit the Cocos Page & download Run the installer to install the Xcode Templates
Concepts
Scenes, Layers, NodesScenes Conceptually a View Controller Managed by the CCDirector
Scenes, Layers, NodesLayers  Logical Separation of elements in the scene
Scenes, Layers, NodesEverything is a CCNode  Sprites, UI Items.  Allows for Parent/Child relationships
Input
Touch InputiOS 3 Style Callbacks  -ccTouchesBegan:withEvent:  -ccTouchesMoved:withEvent:  -ccTouchesEnded:withEvent:  -ccT...
Touch InputNo Gesture RecognizersBest to dig up that legacy code…
Accelerometer InputUses existing UIKit callback  -accelerometer:didAccelerate:Enabled via isAccelerometerEnabled property
Gyro Input?Not out of box :(BUT, CoreMotion is EASY!
Audio
AudioCocosDenshion Primary  Includes SimpleAudioEngine wrapperAlternate is ObjectAL
SimpleAudioEngineObtain SimpleAudioEngine instancePreload, Play or Unlock  [audioEngine preloadEffect:filename]  [audioEng...
SimpleAudioEngine (cont)Obtain SimpleAudioEngine instancePreload or Play Music  [audioEngine preloadBackgroundMusic:filena...
The Demo Game
Conclusion
Resources (Code)Cocos2D: http://www.cocos2d-iphone.org/ShooterDemo: https://github.com/robc/ShooterDemo
Resources (Tools)cfxr: http://thirdcog.eu/apps/cfxrTexturePacker: http://www.texturepacker.comGlyphDesigner: glyphdesigner...
Resources (Books)Learning Cocos2D: http://cocos2dbook.com/Learn Cocos2D Game Development*: http://www.learn-cocos2d.com/st...
Cocos2D Introduction (Melbourne Cocoaheads 20111013)
Cocos2D Introduction (Melbourne Cocoaheads 20111013)
Cocos2D Introduction (Melbourne Cocoaheads 20111013)
Cocos2D Introduction (Melbourne Cocoaheads 20111013)
Cocos2D Introduction (Melbourne Cocoaheads 20111013)
Cocos2D Introduction (Melbourne Cocoaheads 20111013)
Cocos2D Introduction (Melbourne Cocoaheads 20111013)
Cocos2D Introduction (Melbourne Cocoaheads 20111013)
Upcoming SlideShare
Loading in …5
×

Cocos2D Introduction (Melbourne Cocoaheads 20111013)

1,417 views
1,364 views

Published on

A brief introduction to the Cocos2D game engine for iOS devices covering some of the basic architecture and usage.

Published in: Technology, Travel
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,417
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
27
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • 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
  • Cocos2D Introduction (Melbourne Cocoaheads 20111013)

    1. 1. Cocos2D: An introductionRob Caporetto (@rob_caporetto)www.rob-caporetto.com
    2. 2. Caveats
    3. 3. What is Cocos2D?
    4. 4. Getting Up & Running
    5. 5. Installing Visit the Cocos Page & download Run the installer to install the Xcode Templates
    6. 6. Installing Visit the Cocos Page & download Run the installer to install the Xcode Templates
    7. 7. Concepts
    8. 8. Scenes, Layers, NodesScenes Conceptually a View Controller Managed by the CCDirector
    9. 9. Scenes, Layers, NodesLayers Logical Separation of elements in the scene
    10. 10. Scenes, Layers, NodesEverything is a CCNode Sprites, UI Items. Allows for Parent/Child relationships
    11. 11. Input
    12. 12. Touch InputiOS 3 Style Callbacks -ccTouchesBegan:withEvent: -ccTouchesMoved:withEvent: -ccTouchesEnded:withEvent: -ccTouchesCancelled:withEvent:Enable with isTouchEnabled on Layer
    13. 13. Touch InputNo Gesture RecognizersBest to dig up that legacy code…
    14. 14. Accelerometer InputUses existing UIKit callback -accelerometer:didAccelerate:Enabled via isAccelerometerEnabled property
    15. 15. Gyro Input?Not out of box :(BUT, CoreMotion is EASY!
    16. 16. Audio
    17. 17. AudioCocosDenshion Primary Includes SimpleAudioEngine wrapperAlternate is ObjectAL
    18. 18. SimpleAudioEngineObtain SimpleAudioEngine instancePreload, Play or Unlock [audioEngine preloadEffect:filename] [audioEngine playEffect:filename] [audioEngine unloadEffect:filename]
    19. 19. SimpleAudioEngine (cont)Obtain SimpleAudioEngine instancePreload or Play Music [audioEngine preloadBackgroundMusic:filename] [audioEngine playBackgroundMusic:file loop:YES] [audioEngine stopBackgroundMusic:filename]
    20. 20. The Demo Game
    21. 21. Conclusion
    22. 22. Resources (Code)Cocos2D: http://www.cocos2d-iphone.org/ShooterDemo: https://github.com/robc/ShooterDemo
    23. 23. Resources (Tools)cfxr: http://thirdcog.eu/apps/cfxrTexturePacker: http://www.texturepacker.comGlyphDesigner: glyphdesigner.71squared.com
    24. 24. Resources (Books)Learning Cocos2D: http://cocos2dbook.com/Learn Cocos2D Game Development*: http://www.learn-cocos2d.com/store/book-learn-cocos2d/

    ×