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
74
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
680
How to make a simple virtual machine
csl
1
1.2k
Interpreting DNA with Python
csl
2
220
R⁷RS Scheme
csl
0
360
The Mace Model Checker
csl
0
89
Bootstrap, LeSS and CoffeeScript
csl
0
66
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
RailsConf 2023
tenderlove
29
940
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
We Have a Design System, Now What?
morganepeng
51
7.3k
Thoughts on Productivity
jonyablonski
68
4.4k
Rails Girls Zürich Keynote
gr2m
94
13k
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!