Cocos2Dfor iOSByGibson TangAzukisoft Pte Ltd22 – 12 - 2012(The day after the Mayan prediction of the end of the world)
Binary size max is                               64 kb, not 64 MBWho Am I?Mobile Developer since 2004Ex Nokia SymbianEx J2...
What is Cocos2DPopular Objective-C game engineEasy to useTons of supportOpen source and free (Very important)
Cocos2DUsed in thousands of gamesCreator of Cocos2D was acqui-hired byZyngaYes, the Zynga whose stock is tanking now
What is Cocos2DHas a lot of portsCocos2d-x for Android and cross platformCocos2d html5Cocos2d for Blackberry etc
What is Cocos2Dhttp://www.cocos2d-iphone.org/downloadGo download it now
Cocos2DDirector – The guy that calls the shotsScenes – Director manages scenesLayers – Scenes can comprise of 1 or morelay...
Cocos2D
ScenesThink of a scene as a screenSo in a game, you may have a• Starting scene• Gameplay scene• Results sceneetc
LayersA scene can have > 1 layersThink of a layer in the same vein as a layer ina Photoshop PSD fileSame concept 
CCNodeCCNode is the base class that almost allCocos2D classes inherit fromThis has common properties such as- Position- Z ...
OriginThe coordinate system starts from bottomleft of screen    Y          Hope you still remember          your Cartesian...
Cocos2DAll classes and objects have the prefix ‘CC’• CCSprite• CCAction• CCMoveByetc
CCSpriteAn image object that loads in a png fileCCSprite *sprite = [CCSpritespriteWithFile:@”man.png”];
Sprite MovementCocos2d has a vast array of actions•   Movement•   Scaling•   Fading•   Rotation•   etc•   http://www.cocos...
Sprite• After loading a sprite• Need call the ‘add’ method• To add the sprite to another sprite• Or add to a scene• Then t...
Sprite BasicsCCSprite *sprite = [CCSpritespriteWithFile:@”man.png”];• [self addChild:sprite];• [sprite runAction:[CCMoveTo...
UIKitSo what happens if you want to integrate UIKitelement?• Textfield• Alertview• WebviewCan you do that with Cocos2D?
UIKitYes, you can. Most common way is to add themin using codeUIAlertView* alert_view = [[UIAlertViewalloc] initWithTitle:...
UIKit
UIKitYes, you can. Most common way is to addthem in using code UIView *myView = (UIView*) [[CCDirectorsharedDirector] open...
UIKit
UIKitYes, you can also add your xibs into Cocos2Dhttp://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit
Audio• To play audio is very simple• Just #import “SimpleAudioEngine.h”• Then call the methods to play the audio   • Backg...
Audio• [[SimpleAudioEngine sharedEngine]  preloadEffect:@"sfx.wav"];  //sfx.wav is the name of the sound file• [[SimpleAud...
It’s Demo TimeI am going to show you how to create asimple game-   Game mechanics is simple-   Tap the snails to squash th...
Download Code• http://www.azukisoft.com/Helloi  OSDevs.zip
Cocos2d for beginners
Upcoming SlideShare
Loading in …5
×

Cocos2d for beginners

2,535 views

Published on

Cocos2d iPhone game development given for the iOS Dev Scout on 22nd Dec 2012 conducted at Blk 71 Plug-in. Yummy food courtesy of IDA

Published in: Entertainment & Humor
  • Be the first to like this

Cocos2d for beginners

  1. 1. Cocos2Dfor iOSByGibson TangAzukisoft Pte Ltd22 – 12 - 2012(The day after the Mayan prediction of the end of the world)
  2. 2. Binary size max is 64 kb, not 64 MBWho Am I?Mobile Developer since 2004Ex Nokia SymbianEx J2ME developerCurrently Android and iPhonedeveloper
  3. 3. What is Cocos2DPopular Objective-C game engineEasy to useTons of supportOpen source and free (Very important)
  4. 4. Cocos2DUsed in thousands of gamesCreator of Cocos2D was acqui-hired byZyngaYes, the Zynga whose stock is tanking now
  5. 5. What is Cocos2DHas a lot of portsCocos2d-x for Android and cross platformCocos2d html5Cocos2d for Blackberry etc
  6. 6. What is Cocos2Dhttp://www.cocos2d-iphone.org/downloadGo download it now
  7. 7. Cocos2DDirector – The guy that calls the shotsScenes – Director manages scenesLayers – Scenes can comprise of 1 or morelayersIt is a game engine based on concept ofnodes
  8. 8. Cocos2D
  9. 9. ScenesThink of a scene as a screenSo in a game, you may have a• Starting scene• Gameplay scene• Results sceneetc
  10. 10. LayersA scene can have > 1 layersThink of a layer in the same vein as a layer ina Photoshop PSD fileSame concept 
  11. 11. CCNodeCCNode is the base class that almost allCocos2D classes inherit fromThis has common properties such as- Position- Z order- Tag- etc
  12. 12. OriginThe coordinate system starts from bottomleft of screen Y Hope you still remember your Cartesian Math 0,0 X
  13. 13. Cocos2DAll classes and objects have the prefix ‘CC’• CCSprite• CCAction• CCMoveByetc
  14. 14. CCSpriteAn image object that loads in a png fileCCSprite *sprite = [CCSpritespriteWithFile:@”man.png”];
  15. 15. Sprite MovementCocos2d has a vast array of actions• Movement• Scaling• Fading• Rotation• etc• http://www.cocos2d-iphone.org/api- ref/2.1.0/interface_c_c_action.html
  16. 16. Sprite• After loading a sprite• Need call the ‘add’ method• To add the sprite to another sprite• Or add to a scene• Then the game engine handles the rendering for you• Easy as Pie
  17. 17. Sprite BasicsCCSprite *sprite = [CCSpritespriteWithFile:@”man.png”];• [self addChild:sprite];• [sprite runAction:[CCMoveTo actionWithDuration: 2.0f position:ccp(240, 320)]]; This moves man.png to position 240, 320 using 2 seconds
  18. 18. UIKitSo what happens if you want to integrate UIKitelement?• Textfield• Alertview• WebviewCan you do that with Cocos2D?
  19. 19. UIKitYes, you can. Most common way is to add themin using codeUIAlertView* alert_view = [[UIAlertViewalloc] initWithTitle:@”Title"message:@"Your Message" delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil];[alert_view setDelegate:self];[alert_view show];[alert_view autorelease];
  20. 20. UIKit
  21. 21. UIKitYes, you can. Most common way is to addthem in using code UIView *myView = (UIView*) [[CCDirectorsharedDirector] openGLView];//get the view textField = [[UITextField alloc]initWithFrame:CGRectMake(40, 168, 250, 40)]; [myView addSubview:textField]; [[[[CCDirector sharedDirector]openGLView]window]addSubview:myView];[myView setDelegate:self];
  22. 22. UIKit
  23. 23. UIKitYes, you can also add your xibs into Cocos2Dhttp://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit
  24. 24. Audio• To play audio is very simple• Just #import “SimpleAudioEngine.h”• Then call the methods to play the audio • Background music • Effect• mp3, wav, caf (Core Audio Format) files can be used
  25. 25. Audio• [[SimpleAudioEngine sharedEngine] preloadEffect:@"sfx.wav"]; //sfx.wav is the name of the sound file• [[SimpleAudioEngine sharedEngine] playEffect:@"sfx.wav"]; //play the audio file sfx.wav• [[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"bgm.mp3"]; //play the bgm.mp3 background music
  26. 26. It’s Demo TimeI am going to show you how to create asimple game- Game mechanics is simple- Tap the snails to squash them- Before they reach the end of the screen- It won’t be the next Angry Birds- But it’s a start
  27. 27. Download Code• http://www.azukisoft.com/Helloi OSDevs.zip

×