ios gaming with cocos2d
TRANSCRIPT
![Page 1: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/1.jpg)
iOS gaming with cocos2d
Prepared by Ngo Duc Hiep
Copyright 2011 PTT Solution ., JSC. All rights reserved.
Hanoi, May 2011
![Page 2: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/2.jpg)
iOS game engines
Sparrow
Galaxyoolong
cocos2d
![Page 3: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/3.jpg)
iOS game engines
Corona
iTorque
Game salad
Unity
![Page 4: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/4.jpg)
iOS game engines
http://maniacdev.com/2011/01/open-source-and-commercial-ios-game-engine-listings-updated/
http://maniacdev.com/2009/09/the-commercial-iphone-game-engine-comparison-3d-and-2d/
![Page 5: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/5.jpg)
cocos2d games
Tap Pet Hotel: #1 Free
Tap Zoo: #2 Free
Zombie Farm: #6 Free
iStunt 2: #6 Free
![Page 6: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/6.jpg)
cocos2d games
Trainyard: #2 Paid
ZombieSmash: #1 Paid
Air Penguin: #1 Paid
Fishing Frenzy: #7 Paid
![Page 7: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/7.jpg)
cocos2d
![Page 8: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/8.jpg)
App workflow
Loading Home
Leaderboard
Game Play
Settings
![Page 9: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/9.jpg)
App workflow
CCScene
CCDirector: run, push, pop replace scene
[[CCDirector sharedDirector] runWithScene:loading];
[[CCDirector sharedDirector] replaceScene:home];
CCTransition: transition between scenes
![Page 10: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/10.jpg)
CCLayer
![Page 11: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/11.jpg)
CCLayer
Handle event
isTouchEnabled_
isAccelerometerEnabled_
Game controller
Mange game entities - CCNode
![Page 12: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/12.jpg)
CCNode
Renderable item
CCLayer, CCScene are all nodes
Features
Contains another nodes
Schedule timer
Play actions
Position/rotation/scale/contentSize
![Page 13: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/13.jpg)
CCSprite
Sprites
Texture
![Page 14: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/14.jpg)
CCNode: CoordinatecontentSize.width
conte
ntS
ize.h
eig
ht
![Page 15: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/15.jpg)
CCNode: Coordinate
rotation
positio
nanchorPoint
![Page 16: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/16.jpg)
CCNode: Coordinate
![Page 17: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/17.jpg)
CCNode: Transformation
- (CGAffineTransform)nodeToParentTransform;
- (CGAffineTransform)parentToNodeTransform;
- (CGAffineTransform)nodeToWorldTransform;
- (CGAffineTransform)worldToNodeTransform;
- (CGPoint)convertToNodeSpace:(CGPoint)worldPoint;
- (CGPoint)convertToWorldSpace:(CGPoint)nodePoint;
![Page 18: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/18.jpg)
CCNode: Actions
Modify node’s attributes by time
position/rotation/scale/opacity/grid
Interval actions and Instant actions
![Page 19: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/19.jpg)
CCNode: Actions
CCMove_
CCJump_
CCBezier_
CCScale_
CCRotate_
CCFade_
![Page 20: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/20.jpg)
CCNode: Actions
Time alter actions:
• CCEase_
• CCEaseExponential_
• CCEaseSine_
• CCEaseElastic_
• CCEaseBounce_
![Page 21: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/21.jpg)
CCNode: Special actions
CCCallFunc
CCCallBlock
CCPropertyAction
CCFollow
CCSequence
CCSpawn
CCRepeat
![Page 22: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/22.jpg)
CCNode: 3D Effects
CCFlipX3D/CCFlipY3D
CCWaves3D
CCRipple3D
CCSplitRows
…
![Page 23: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/23.jpg)
CCSprite: Animation
![Page 24: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/24.jpg)
CCSprite: Animation
![Page 25: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/25.jpg)
CCNode: Scheduler
-(void) schedule: (SEL) s interval:(ccTime)seconds;
-(void) unschedule: (SEL) s;
-(void) pauseSchedulerAndActions;
-(void) resumeSchedulerAndActions;
![Page 26: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/26.jpg)
Touch Dispathcher
CCTouchDispathcher
-(void) addStandardDelegate:(id) delegate priority:(int)priority;
-(void) addTargetedDelegate:(id) delegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches;
-(void) removeDelegate:(id) delegate;
![Page 27: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/27.jpg)
Box2D
![Page 28: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/28.jpg)
Features
Rigid body Fixture: rectangle, circle, poligon
Joint
Contact filter
Contact listener
Simulate
world->Step(dt);
![Page 29: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/29.jpg)
cocos2d Box2D
Body, joint, fixture user data
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
if (b->GetUserData() != NULL) {
CCSprite *actor = (CCSprite*)b->GetUserData();
actor.position = CGPointMake( b->GetPosition().x , b->GetPosition().y);
actor.rotation = -b->GetAngle() * 180 / M_PI;
}
}
![Page 30: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/30.jpg)
Car
Cocos2d
ccCarBody
ccCarWheel1
ccCarWhell2
Box2D
b2CarBody
b2CarWheel1
b2CarWhell2
b2CarJoint1
b2CarJoint2
![Page 31: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/31.jpg)
cocos2d+ext
![Page 32: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/32.jpg)
CCNode+ext
Transform
- (CGAffineTransform) nodeToNodeTransform:
(CCNode *) node;
- (CGAffineTransform) nodeFromNodeTransform:
(CCNode *) node;
![Page 33: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/33.jpg)
CCNode+ext
Transform
Collision
- (CGRect) rect;
- (BOOL) isCollideWithNode:(CCNode *) node;
![Page 34: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/34.jpg)
CCNode+ext
Transform
Collision
Containing
- (BOOL) containsPoint:(CGPoint) loc;
- (BOOL) containsTouch:(UITouch *) touch;
![Page 35: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/35.jpg)
CCSprite+ext - (CCAction *) animateFramesWithKey:(NSString *) key
startIndex:(int) start
endIndex:(int) end
duration:(float) duration
reverse:(BOOL) reverse
forever:(BOOL) forever;
![Page 36: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/36.jpg)
CCComponent
Independent, portable
States control
Data driven
Callbacks
Physics support
Composition
![Page 37: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/37.jpg)
CCComponent
Data
Texture file
Texture def file
Component def fileStatesChilds
![Page 38: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/38.jpg)
CCComponent
States
Animate frames
Rotate
Scale
Fade
![Page 39: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/39.jpg)
CCComponent
Lion_jump_1.png
Lion_jump_4.pngLion_jump_3.png
Lion_jump_2.png
![Page 40: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/40.jpg)
CCComponent
Lion “jump” state:
key=Lion_jump_
type=frame
startframe=1
endframe=4
duration=0.1
forever=NO
lion.state = @”jump”;
![Page 41: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/41.jpg)
CCComponent
- (void) setState:(NSString *) state;
- (void) setState:(NSString *) state target:(NSString *) target selector:(SEL) selector;
- (void) spawnStates:(NSString *) state1,…;
- (void) setStateSequence:(NSString *) state1, …;
![Page 42: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/42.jpg)
CCLayer+ext
Actors group addChild:(CCNode *) child group:(int) gid; removeChild:(CCNode *) child group:(int) gid;
![Page 43: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/43.jpg)
CCLayer+ext
Contacts listener addContactListenerBetweenGroup:(int) g1 andGroup:(int)
g2 selector:(SEL) listener;
- (void) hero:(Hero *) hero collideWith:(Bullet *) bullet{
hero.blood -= bullet.effect;
[bullet explode];
}
![Page 44: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/44.jpg)
CCLayer+ext
Touch helper - (CGPoint) pointForTouches:(NSSet *) touches; - (CGPoint) pointForTouch:(UITouch *) touch; - (CCNode *) getActorAtPoint:(CGPoint) pos; - (CCNode *) getActorAtTouch:(UITouch *) touch;
![Page 45: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/45.jpg)
Tools
![Page 46: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/46.jpg)
Texture: texturetool, TexturePacker, Zwoptex
Tile map editor: Tiled
SVG editor: Inkscape, svg-edit Level design
Particle: Particle Designer
Font editor: Hiero
Audio: Audacity
3D: Blender
![Page 47: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/47.jpg)
Learning resources
![Page 48: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/48.jpg)
http://cs193p.stanford.edu
https://developer.apple.com/itunes/?destination=adc.apple.com.4092414566
http://www.71squared.com/
http://www.raywenderlich.com/
http://iphonedevelopment.blogspot.com/
http://maniacdev.com
http://iphonedev.net/
http://www.learn-cocos2d.com/
http://cocoawithlove.com/
https://github.com/hiepnd
![Page 49: iOS Gaming with Cocos2d](https://reader034.vdocuments.us/reader034/viewer/2022042601/554bd5e0b4c9058f6c8b50ae/html5/thumbnails/49.jpg)
Demo & QA