Presentation 121223112735-phpapp01
-
Upload
sagaroceanic11 -
Category
Technology
-
view
74 -
download
1
Transcript of Presentation 121223112735-phpapp01
![Page 1: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/1.jpg)
Cocos2Dfor iOS
![Page 2: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/2.jpg)
What is Cocos2DPopular Objective-C game engine
Easy to use
Tons of support
Open source and free (Very important)
![Page 3: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/3.jpg)
Cocos2DUsed in thousands of games
Creator of Cocos2D was acqui-hired by Zynga
Yes, the Zynga whose stock is tanking now
![Page 4: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/4.jpg)
![Page 5: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/5.jpg)
What is Cocos2DHas a lot of ports
Cocos2d-x for Android and cross platform
Cocos2d html5
Cocos2d for Blackberry etc
![Page 6: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/6.jpg)
What is Cocos2Dhttp://www.cocos2d-iphone.org/download
Go download it now
![Page 7: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/7.jpg)
Cocos2DDirector – The guy that calls the shots
Scenes – Director manages scenes
Layers – Scenes can comprise of 1 or more layers
It is a game engine based on concept of nodes
![Page 8: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/8.jpg)
Cocos2D
![Page 9: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/9.jpg)
ScenesThink of a scene as a screen
So in a game, you may have a• Starting scene• Gameplay scene• Results sceneetc
![Page 10: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/10.jpg)
LayersA scene can have > 1 layers
Think of a layer in the same vein as a layer in a Photoshop PSD file
Same concept
![Page 11: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/11.jpg)
CCNodeCCNode is the base class that almost all Cocos2D classes inherit from
This has common properties such as - Position- Z order- Tag- etc
![Page 12: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/12.jpg)
OriginThe coordinate system starts from bottom left of screen
0,0 X
Y
Hope you still remember your Cartesian Math
![Page 13: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/13.jpg)
Cocos2DAll classes and objects have the prefix ‘CC’
• CCSprite
• CCAction
• CCMoveBy
etc
![Page 14: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/14.jpg)
CCSpriteAn image object that loads in a png file
CCSprite *sprite = [CCSprite spriteWithFile:@”man.png”];
![Page 15: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/15.jpg)
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
![Page 16: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/16.jpg)
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
![Page 17: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/17.jpg)
Sprite Basics
CCSprite *sprite = [CCSprite spriteWithFile:@”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
![Page 18: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/18.jpg)
UIKitSo what happens if you want to integrate UIKit element?
• Textfield
• Alertview
• Webview
Can you do that with Cocos2D?
![Page 19: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/19.jpg)
UIKitYes, you can. Most common way is to add them in using code
UIAlertView* alert_view = [[UIAlertView alloc] initWithTitle:@”Title" message:@"Your Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];[alert_view setDelegate:self];[alert_view show];[alert_view autorelease];
![Page 20: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/20.jpg)
UIKit
![Page 21: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/21.jpg)
UIKitYes, you can. Most common way is to add them in using code
UIView *myView = (UIView*) [[CCDirector sharedDirector] 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];
![Page 22: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/22.jpg)
UIKit
![Page 23: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/23.jpg)
UIKitYes, you can also add your xibs into Cocos2D
http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit
![Page 24: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/24.jpg)
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
![Page 25: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/25.jpg)
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
![Page 26: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/26.jpg)
It’s Demo TimeI am going to show you how to create a simple 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
![Page 27: Presentation 121223112735-phpapp01](https://reader035.fdocuments.net/reader035/viewer/2022081603/55820faed8b42ac7728b4673/html5/thumbnails/27.jpg)
Download Code
•http://www.azukisoft.com/HelloiOSDevs.zip