cocos2d & Chipmunk2D games development for iOSKonrad Kołakowski, Playsoft
cocos2dWhat is it?
cocos2d - what was made with it?Kingdom Rush
cocos2d - what was made with it?Robot Unicorn Attack
cocos2d - what was made with it?League of Evil
ChipmunkWhat is it?
Chipmunk - what was made with it?Waking Mars
Chipmunk - what was made with it?Feed me Oil
Chipmunk - what was made with it?I Dig It
Creating project in Xcode1. Download cocos2d-iphone: www.cocos2d-iphone.org/download2. If you want to comfortably creating...
Creating project in XcodeThats all, in this moment, after creating aproject you should see following options:
Creating project in XcodeAs you can see cocos2d delivers Chipmunkcode in theirs templates.Beside Chipmunk there is also ve...
cocos2d basics - layers, nodescocos2d logic is divided to scenes. Scene is amain node to which we connect next ones (layer...
Podstawy cocos2d - warstwy, węzły
cocos2d basics - layers, nodes
cocos2d basics - coordinatesCoordinate system, anchor points.
cocos2d basics - adding elementsHow to draw such an alien?// GameScene.h#import "cocos2d.h"@interface GameScene : CCScene@...
// GameScene.m#import "GameScene.h"@implementation GameScene-(id) init {self = [super init];if(self) {// 1CGSize s = [CCDi...
To enable gathering touch events on our layer:[self setIsTouchEnabled: YES];Next we need to implement CCStandardTouchDeleg...
cocos2d basics - touch support- (void)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{for( UITouch *touch in touc...
cocos2d basics - actionsActions are a nice element of cocos2dframework. They allow to easily createuncomplicated animation...
cocos2d basics - actions
cocos2d basics - actions
Following code will cause that our invader willturn around and move by 50 points. Everythingin one second.-(void) roll {CC...
- creating/destroying all objects should beperformed through cpSpaceNew,cpSpaceFree, cpBodyNew, etc.- to configure and cre...
Chipmunk basics - physical objectsConcept of shape and body:A body is a physical state ( mass, position,rotation... ) and ...
Creating a "floor"// 1CGSize s = [CCDirector sharedDirector].winSize;CGPoint lowerLeft = ccp(0, 0);CGPoint lowerRight = cc...
Creating and adding a rectangle object:static const float boxW = 30.0f;static const float boxH = 50.0f;static const float ...
Chipmunk basics - starting asimulation// Inside a layer init method[self scheduleUpdate];// update is called every frame-(...
SummaryThose are only the basics of those twoframeworks, more things are waiting todiscover!Official documentation:chipmun...
Questions?
Konrad Kołakowskikonrad.kolakowski@me.com
Upcoming SlideShare
Loading in …5
×

2013-04-16 cocos2d & chipmunk

780 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
780
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

2013-04-16 cocos2d & chipmunk

  1. 1. cocos2d & Chipmunk2D games development for iOSKonrad Kołakowski, Playsoft
  2. 2. cocos2dWhat is it?
  3. 3. cocos2d - what was made with it?Kingdom Rush
  4. 4. cocos2d - what was made with it?Robot Unicorn Attack
  5. 5. cocos2d - what was made with it?League of Evil
  6. 6. ChipmunkWhat is it?
  7. 7. Chipmunk - what was made with it?Waking Mars
  8. 8. Chipmunk - what was made with it?Feed me Oil
  9. 9. Chipmunk - what was made with it?I Dig It
  10. 10. Creating project in Xcode1. Download cocos2d-iphone: www.cocos2d-iphone.org/download2. If you want to comfortably creating newgames, install templates for Xcode ( run thiscommand in Terminal ):./install-templates.sh -f -u
  11. 11. Creating project in XcodeThats all, in this moment, after creating aproject you should see following options:
  12. 12. Creating project in XcodeAs you can see cocos2d delivers Chipmunkcode in theirs templates.Beside Chipmunk there is also version withBox2D integrated, similar 2D physics.
  13. 13. cocos2d basics - layers, nodescocos2d logic is divided to scenes. Scene is amain node to which we connect next ones (layers, sprites, particle effects etc. )Each element added to the game ( exceptscenes ) have to be added to some parentelement.
  14. 14. Podstawy cocos2d - warstwy, węzły
  15. 15. cocos2d basics - layers, nodes
  16. 16. cocos2d basics - coordinatesCoordinate system, anchor points.
  17. 17. cocos2d basics - adding elementsHow to draw such an alien?// GameScene.h#import "cocos2d.h"@interface GameScene : CCScene@end
  18. 18. // GameScene.m#import "GameScene.h"@implementation GameScene-(id) init {self = [super init];if(self) {// 1CGSize s = [CCDirector sharedDirector].winSize;// 2CCSprite* invader = [CCSprite spriteWithFile: @"invader.png" ];invader.position = ccp(s.width/ 2, s.height/2);// 3[self addChild: invader];}return self;}@endcocos2d basics - adding elements
  19. 19. To enable gathering touch events on our layer:[self setIsTouchEnabled: YES];Next we need to implement CCStandardTouchDelegatemethods:- (void)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;- (void)ccTouchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;- (void)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;- (void)ccTouchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event;cocos2d basics - touch support
  20. 20. cocos2d basics - touch support- (void)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{for( UITouch *touch in touches ) {CGPoint pos = [touch locationInView: [touch view]];pos = [[CCDirector sharedDirector] convertToGL:location];// Do something with position// (...)}}
  21. 21. cocos2d basics - actionsActions are a nice element of cocos2dframework. They allow to easily createuncomplicated animations or repeated logic.Especially with Obj-C blocks.We can join actions in sequences, addingeasing etc.
  22. 22. cocos2d basics - actions
  23. 23. cocos2d basics - actions
  24. 24. Following code will cause that our invader willturn around and move by 50 points. Everythingin one second.-(void) roll {CCMoveBy* move = [CCMoveBy actionWithDuration: 1.0fposition: ccp( 50.0f, 0.0f)];CCRotateBy* rotate = [CCRotateBy actionWithDuration: 1.0fangle: 360.0f];[invader_ runAction: move];[invader_ runAction: rotate];}cocos2d basics - actions
  25. 25. - creating/destroying all objects should beperformed through cpSpaceNew,cpSpaceFree, cpBodyNew, etc.- to configure and create a space:cpSpace* space = cpSpaceNew();cpSpaceSetGravity(space, ccp(0.0f, -500.0f));Chipmunk basics - creating a space
  26. 26. Chipmunk basics - physical objectsConcept of shape and body:A body is a physical state ( mass, position,rotation... ) and shapes are used forrecognizing collisions.
  27. 27. Creating a "floor"// 1CGSize s = [CCDirector sharedDirector].winSize;CGPoint lowerLeft = ccp(0, 0);CGPoint lowerRight = ccp(s.width, 0);float height = 20.0f;// 2cpBody* groundBody = cpBodyNewStatic();// 3cpShape* groundShape = cpSegmentShapeNew(groundBody, lowerLeft, lowerRight,height);cpShapeSetElasticity(groundShape, 0.2f);cpShapeSetFriction(groundShape, 1.0f);// 4cpSpaceAddShape(space, groundShape);Chipmunk basics - physical objects
  28. 28. Creating and adding a rectangle object:static const float boxW = 30.0f;static const float boxH = 50.0f;static const float mass = 2.5f;cpBody* body = cpBodyNew(mass, cpMomentForBox(mass, boxW,boxH));cpBodySetPosition(body, ccp(s.width/2, s.height/2));cpSpaceAddBody(space, body);cpShape* shape = cpBoxShapeNew(body, boxW, boxH);cpShapeSetElasticity(shape, 0.8f);cpShapeSetFriction(shape, 1.0f);cpSpaceAddShape(space, shape);Chipmunk basics - physical objects
  29. 29. Chipmunk basics - starting asimulation// Inside a layer init method[self scheduleUpdate];// update is called every frame-(void) update:(ccTime)dt {cpSpaceStep(space, dt);}
  30. 30. SummaryThose are only the basics of those twoframeworks, more things are waiting todiscover!Official documentation:chipmunk-physics.net/release/ChipmunkLatest-Docswww.cocos2d-iphone.org/api-ref/latest-stable
  31. 31. Questions?
  32. 32. Konrad Kołakowskikonrad.kolakowski@me.com

×