Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
iPhone game programming with Cocos2D
Search
Christian Stigen Larsen
October 11, 2011
0
67
iPhone game programming with Cocos2D
Norwegian presentation at Bouvet on iPhone game programming using Cocos2D and physics engines.
Christian Stigen Larsen
October 11, 2011
Tweet
Share
More Decks by Christian Stigen Larsen
See All by Christian Stigen Larsen
Writing a basic x86-64 JIT compiler from scratch in stock Python
csl
0
310
The Busy Beaver Game
csl
0
660
How to make a simple virtual machine
csl
1
1.2k
Interpreting DNA with Python
csl
2
220
R⁷RS Scheme
csl
0
340
The Mace Model Checker
csl
0
82
Bootstrap, LeSS and CoffeeScript
csl
0
65
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Into the Great Unknown - MozCon
thekraken
31
1.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
504
140k
How GitHub (no longer) Works
holman
311
140k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
Making Projects Easy
brettharned
115
5.9k
Designing Experiences People Love
moore
138
23k
Testing 201, or: Great Expectations
jmmastey
38
7k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
Build The Right Thing And Hit Your Dates
maggiecrowley
32
2.4k
Transcript
iPhone spillutvikling med Christian Stigen Larsen, CODE
None
None
None
None
None
None
None
None
None
None
None
• iOS
• iOS • Cocos2D + fysikkmotorer
• iOS • Cocos2D + fysikkmotorer • Spill i Objective-C
iOS
iOS Devices
iOS Devices
iOS Devices
iOS Devices
iOS SDK
iOS SDK Core OS
iOS SDK Core OS Core Services
iOS SDK Core OS Core Services Media Layer
iOS SDK Core OS Core Services Media Layer Cocoa Touch
iOS SDK Cocos2D Core OS Core Services Media Layer Cocoa
Touch
Cocos2D konsepter
Cocos2D konsepter • Sprites + actions
Cocos2D konsepter • Sprites + actions • Layers
Cocos2D konsepter • Sprites + actions • Layers • Scenes
Cocos2D konsepter • Sprites + actions • Layers • Scenes
• Director
Cocos2D konsepter • Sprites + actions • Layers • Scenes
• Director • Fysikkmotor
Sprites
Sprites
Sprites
Sprites
Sprites
Sprites
Sprites
Sprites
Sprites
Sprites
Sprites
Layers
Layers
Layers
Layers
Layers
Layers
Layers
Layers
Layers
Layers
Layers
Layers
Layers
Layers
Layers
Scenes
Scenes Hovedmeny
Scenes Hovedmeny Level 1 ... n
Scenes Hovedmeny Level 1 ... n Game Over
Director Hovedmeny Level 1 ... n Game Over
Director Hovedmeny Level 1 ... n Game Over
Director Hovedmeny Level 1 ... n Game Over
Director Hovedmeny Level 1 ... n Game Over
Fysikkmotor
Fysikkmotor • Chipmunk
Fysikkmotor • Chipmunk • Box2D
None
None
Objective-C
Objective-C Krasjkurs
Objective-C Krasjkurs
Objective-C Krasjkurs • C + Smalltalk
Objective-C Krasjkurs • C + Smalltalk • Reference counting
Objective-C Krasjkurs • C + Smalltalk • Reference counting •
Xcode og llvm
Metodekall Krasjkurs
Metodekall Krasjkurs [objekt metodeNavn];
Metodekall Krasjkurs [objekt metodeNavn];
Metodekall Krasjkurs [objekt metodeNavn]; [objekt metodeNavn:param1];
Metodekall Krasjkurs [objekt metodeNavn]; [objekt metodeNavn:param1]; [sprite showInLayer:layer1 x:100 y:200
scaleBy:2.0f];
Instansiering Krasjkurs
Instansiering Krasjkurs Bird *b = [[Bird alloc] initWithSpeed:speed andSprite:sprite];
Instansiering Krasjkurs Bird *b = [[Bird alloc] initWithSpeed:speed andSprite:sprite];
Instansiering Krasjkurs Bird *b = [[Bird alloc] init];WithSpeed:speed andSprite:sprite];
Instansiering Krasjkurs Bird *b = [[Bird alloc] initWithSpeed:speed andSprite:sprite];
Instansiering Krasjkurs Bird *b = [[Bird alloc] initWithSpeed:speed andSprite:sprite]; [b
release];
Klasser Krasjkurs
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite;
float speed; } -(CCSprite*) getSprite; +(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end
Implementasjon Krasjkurs
Implementasjon Krasjkurs @implementation Bird -(CCSprite*) getSprite { return sprite; }
@end
Implementasjon Krasjkurs @implementation Bird -(CCSprite*) getSprite { return sprite; }
@end
Implementasjon Krasjkurs @implementation Bird -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s { self =
[super init]; if ( self ) { speed = v; sprite = s; } return self; } @end
Implementasjon Krasjkurs @implementation Bird -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s { self =
[super init]; if ( self ) { speed = v; sprite = s; } return self; } @end
Implementasjon Krasjkurs @implementation Bird -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s { self =
[super init]; if ( self ) { speed = v; sprite = s; } return self; } @end
Implementasjon Krasjkurs @implementation Bird -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s { self =
[super init]; if ( self ) { speed = v; sprite = s; } return self; } @end
BumblePop
BumblePop
Startup av app
Startup av app iOS
Startup av app - (void) applicationDidFinishLaunching:(UIApplication*)app iOS
Startup av app - (void) applicationDidFinishLaunching:(UIApplication*)app
Startup av app - (void) applicationDidFinishLaunching:(UIApplication*)app { window = [[UIWindow
alloc] initWithFrame:/* ... */]; // ... CCDirector *director = [CCDirector sharedDirector]; [director setAnimationInterval:1.0/60]; [director setDisplayFPS:YES]; // ... [[CCDirector sharedDirector] runWithScene:[HelloWorldLayer scene]]; } - (void) applicationDidFinishLaunching:(UIApplication*)app
Startup av app - (void) applicationDidFinishLaunching:(UIApplication*)app { window = [[UIWindow
alloc] initWithFrame:/* ... */]; // ... CCDirector *director = [CCDirector sharedDirector]; [director setAnimationInterval:1.0/60]; [director setDisplayFPS:YES]; // ... [[CCDirector sharedDirector] runWithScene:[HelloWorldLayer scene]]; } - (void) applicationDidFinishLaunching:(UIApplication*)app
Startup av layer
Startup av layer -(id) init { if ( (self=[super init])
) { game = [[Game alloc] init]; [self schedule:@selector(nextFrame:)]; CCSprite *bee = [CCSprite spriteWithFile: @"BumbleBee40.png"]; [self addChild:bee]; // ... }
Startup av layer -(id) init { if ( (self=[super init])
) { game = [[Game alloc] init]; [self schedule:@selector(nextFrame:)]; CCSprite *bee = [CCSprite spriteWithFile: @"BumbleBee40.png"]; [self addChild:bee]; // ... }
Startup av layer -(id) init { if ( (self=[super init])
) { game = [[Game alloc] init]; [self schedule:@selector(nextFrame:)]; CCSprite *bee = [CCSprite spriteWithFile: @"BumbleBee40.png"]; [self addChild:bee]; // ... }
Startup av layer -(id) init { if ( (self=[super init])
) { game = [[Game alloc] init]; [self schedule:@selector(nextFrame:)]; CCSprite *bee = [CCSprite spriteWithFile: @"BumbleBee40.png"]; [self addChild:bee]; // ... }
Startup av layer CCLabelTTF *score; score = [CCLabelTTF labelWithString:@"Score: ?"
fontName:@"Marker Felt" fontSize:22];
Neste bilde -(void) draw { // Kun TEGNING, ingen oppdatering
av state } - (void) nextFrame:(ccTime)dt { // Kun oppdatering av STATE }
Bevegelse
Bevegelse cloud.position = ccp( cloud.position.x - 10*dt, cloud.position.y);
Bevegelse cloud.position = ccp( cloud.position.x - 10*dt, cloud.position.y); -10 px/sec
Touch
Touch - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint location =
[self convertTouchToNodeSpace: touch]; beeDestination = location; }
Målbevegelse
Målbevegelse [self moveTowards:bee :&beeDestination :2*dt]; - (void) moveTowards: (CCSprite*)from: (CGPoint*)to:
(float)amount { float dx = to->x - from.position.x; float dy = to->y - from.position.y; dx *= amount; dy *= amount; from.position = ccp(from.position.x + dx, from.position.y + dy); }
Målbevegelse [self moveTowards:bee :&beeDestination :2*dt]; - (void) moveTowards: (CCSprite*)from: (CGPoint*)to:
(float)amount { float dx = to->x - from.position.x; float dy = to->y - from.position.y; dx *= amount; dy *= amount; from.position = ccp(from.position.x + dx, from.position.y + dy); }
Målbevegelse [self moveTowards:bee :&beeDestination :2*dt]; - (void) moveTowards: (CCSprite*)from: (CGPoint*)to:
(float)amount { [from runAction: [CCMoveTo actionWithDuration:1.0f position:*to]]; }
Fugler
Fugler // Move ALL birds with their given speed for
( Bird *p in birds ) [self moveTowards:p->sprite :&beeDestination :p->speed*dt];
Kollisjon
Kollisjon -(void) beeHitBy:(CCSprite*)bird { CGRect beeBox = [bee boundingBox]; CGRect
birdBox = [bird boundingBox]; if ( CGRectIntersectsRect(beeBox, birdBox) ) [self killBee]; }
None
None
Oppsummering • iOS • Cocos2D + fysikkmotorer • Spill i
Objective-C
Takk!