Slide 1

Slide 1 text

iPhone spillutvikling med Christian Stigen Larsen, CODE

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

• iOS

Slide 14

Slide 14 text

• iOS • Cocos2D + fysikkmotorer

Slide 15

Slide 15 text

• iOS • Cocos2D + fysikkmotorer • Spill i Objective-C

Slide 16

Slide 16 text

iOS

Slide 17

Slide 17 text

iOS Devices

Slide 18

Slide 18 text

iOS Devices

Slide 19

Slide 19 text

iOS Devices

Slide 20

Slide 20 text

iOS Devices

Slide 21

Slide 21 text

iOS SDK

Slide 22

Slide 22 text

iOS SDK Core OS

Slide 23

Slide 23 text

iOS SDK Core OS Core Services

Slide 24

Slide 24 text

iOS SDK Core OS Core Services Media Layer

Slide 25

Slide 25 text

iOS SDK Core OS Core Services Media Layer Cocoa Touch

Slide 26

Slide 26 text

iOS SDK Cocos2D Core OS Core Services Media Layer Cocoa Touch

Slide 27

Slide 27 text

Cocos2D konsepter

Slide 28

Slide 28 text

Cocos2D konsepter • Sprites + actions

Slide 29

Slide 29 text

Cocos2D konsepter • Sprites + actions • Layers

Slide 30

Slide 30 text

Cocos2D konsepter • Sprites + actions • Layers • Scenes

Slide 31

Slide 31 text

Cocos2D konsepter • Sprites + actions • Layers • Scenes • Director

Slide 32

Slide 32 text

Cocos2D konsepter • Sprites + actions • Layers • Scenes • Director • Fysikkmotor

Slide 33

Slide 33 text

Sprites

Slide 34

Slide 34 text

Sprites

Slide 35

Slide 35 text

Sprites

Slide 36

Slide 36 text

Sprites

Slide 37

Slide 37 text

Sprites

Slide 38

Slide 38 text

Sprites

Slide 39

Slide 39 text

Sprites

Slide 40

Slide 40 text

Sprites

Slide 41

Slide 41 text

Sprites

Slide 42

Slide 42 text

Sprites

Slide 43

Slide 43 text

Sprites

Slide 44

Slide 44 text

Layers

Slide 45

Slide 45 text

Layers

Slide 46

Slide 46 text

Layers

Slide 47

Slide 47 text

Layers

Slide 48

Slide 48 text

Layers

Slide 49

Slide 49 text

Layers

Slide 50

Slide 50 text

Layers

Slide 51

Slide 51 text

Layers

Slide 52

Slide 52 text

Layers

Slide 53

Slide 53 text

Layers

Slide 54

Slide 54 text

Layers

Slide 55

Slide 55 text

Layers

Slide 56

Slide 56 text

Layers

Slide 57

Slide 57 text

Layers

Slide 58

Slide 58 text

Layers

Slide 59

Slide 59 text

Scenes

Slide 60

Slide 60 text

Scenes Hovedmeny

Slide 61

Slide 61 text

Scenes Hovedmeny Level 1 ... n

Slide 62

Slide 62 text

Scenes Hovedmeny Level 1 ... n Game Over

Slide 63

Slide 63 text

Director Hovedmeny Level 1 ... n Game Over

Slide 64

Slide 64 text

Director Hovedmeny Level 1 ... n Game Over

Slide 65

Slide 65 text

Director Hovedmeny Level 1 ... n Game Over

Slide 66

Slide 66 text

Director Hovedmeny Level 1 ... n Game Over

Slide 67

Slide 67 text

Fysikkmotor

Slide 68

Slide 68 text

Fysikkmotor • Chipmunk

Slide 69

Slide 69 text

Fysikkmotor • Chipmunk • Box2D

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Objective-C

Slide 73

Slide 73 text

Objective-C Krasjkurs

Slide 74

Slide 74 text

Objective-C Krasjkurs

Slide 75

Slide 75 text

Objective-C Krasjkurs • C + Smalltalk

Slide 76

Slide 76 text

Objective-C Krasjkurs • C + Smalltalk • Reference counting

Slide 77

Slide 77 text

Objective-C Krasjkurs • C + Smalltalk • Reference counting • Xcode og llvm

Slide 78

Slide 78 text

Metodekall Krasjkurs

Slide 79

Slide 79 text

Metodekall Krasjkurs [objekt metodeNavn];

Slide 80

Slide 80 text

Metodekall Krasjkurs [objekt metodeNavn];

Slide 81

Slide 81 text

Metodekall Krasjkurs [objekt metodeNavn]; [objekt metodeNavn:param1];

Slide 82

Slide 82 text

Metodekall Krasjkurs [objekt metodeNavn]; [objekt metodeNavn:param1]; [sprite showInLayer:layer1 x:100 y:200 scaleBy:2.0f];

Slide 83

Slide 83 text

Instansiering Krasjkurs

Slide 84

Slide 84 text

Instansiering Krasjkurs Bird *b = [[Bird alloc] initWithSpeed:speed andSprite:sprite];

Slide 85

Slide 85 text

Instansiering Krasjkurs Bird *b = [[Bird alloc] initWithSpeed:speed andSprite:sprite];

Slide 86

Slide 86 text

Instansiering Krasjkurs Bird *b = [[Bird alloc] init];WithSpeed:speed andSprite:sprite];

Slide 87

Slide 87 text

Instansiering Krasjkurs Bird *b = [[Bird alloc] initWithSpeed:speed andSprite:sprite];

Slide 88

Slide 88 text

Instansiering Krasjkurs Bird *b = [[Bird alloc] initWithSpeed:speed andSprite:sprite]; [b release];

Slide 89

Slide 89 text

Klasser Krasjkurs

Slide 90

Slide 90 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 91

Slide 91 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 92

Slide 92 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 93

Slide 93 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 94

Slide 94 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 95

Slide 95 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 96

Slide 96 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 97

Slide 97 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 98

Slide 98 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 99

Slide 99 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; -(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 100

Slide 100 text

Klasser Krasjkurs @interface Bird : NSObject { @public CCSprite *sprite; float speed; } -(CCSprite*) getSprite; +(float) getSpeed; -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s; @end

Slide 101

Slide 101 text

Implementasjon Krasjkurs

Slide 102

Slide 102 text

Implementasjon Krasjkurs @implementation Bird -(CCSprite*) getSprite { return sprite; } @end

Slide 103

Slide 103 text

Implementasjon Krasjkurs @implementation Bird -(CCSprite*) getSprite { return sprite; } @end

Slide 104

Slide 104 text

Implementasjon Krasjkurs @implementation Bird -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s { self = [super init]; if ( self ) { speed = v; sprite = s; } return self; } @end

Slide 105

Slide 105 text

Implementasjon Krasjkurs @implementation Bird -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s { self = [super init]; if ( self ) { speed = v; sprite = s; } return self; } @end

Slide 106

Slide 106 text

Implementasjon Krasjkurs @implementation Bird -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s { self = [super init]; if ( self ) { speed = v; sprite = s; } return self; } @end

Slide 107

Slide 107 text

Implementasjon Krasjkurs @implementation Bird -(Bird*) initWithSpeed:(float)v andSprite:(CCSprite*)s { self = [super init]; if ( self ) { speed = v; sprite = s; } return self; } @end

Slide 108

Slide 108 text

BumblePop

Slide 109

Slide 109 text

BumblePop

Slide 110

Slide 110 text

Startup av app

Slide 111

Slide 111 text

Startup av app iOS

Slide 112

Slide 112 text

Startup av app - (void) applicationDidFinishLaunching:(UIApplication*)app iOS

Slide 113

Slide 113 text

Startup av app - (void) applicationDidFinishLaunching:(UIApplication*)app

Slide 114

Slide 114 text

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

Slide 115

Slide 115 text

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

Slide 116

Slide 116 text

Startup av layer

Slide 117

Slide 117 text

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]; // ... }

Slide 118

Slide 118 text

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]; // ... }

Slide 119

Slide 119 text

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]; // ... }

Slide 120

Slide 120 text

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]; // ... }

Slide 121

Slide 121 text

Startup av layer CCLabelTTF *score; score = [CCLabelTTF labelWithString:@"Score: ?" fontName:@"Marker Felt" fontSize:22];

Slide 122

Slide 122 text

Neste bilde -(void) draw { // Kun TEGNING, ingen oppdatering av state } - (void) nextFrame:(ccTime)dt { // Kun oppdatering av STATE }

Slide 123

Slide 123 text

Bevegelse

Slide 124

Slide 124 text

Bevegelse cloud.position = ccp( cloud.position.x - 10*dt, cloud.position.y);

Slide 125

Slide 125 text

Bevegelse cloud.position = ccp( cloud.position.x - 10*dt, cloud.position.y); -10 px/sec

Slide 126

Slide 126 text

Touch

Slide 127

Slide 127 text

Touch - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint location = [self convertTouchToNodeSpace: touch]; beeDestination = location; }

Slide 128

Slide 128 text

Målbevegelse

Slide 129

Slide 129 text

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); }

Slide 130

Slide 130 text

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); }

Slide 131

Slide 131 text

Målbevegelse [self moveTowards:bee :&beeDestination :2*dt]; - (void) moveTowards: (CCSprite*)from: (CGPoint*)to: (float)amount { [from runAction: [CCMoveTo actionWithDuration:1.0f position:*to]]; }

Slide 132

Slide 132 text

Fugler

Slide 133

Slide 133 text

Fugler // Move ALL birds with their given speed for ( Bird *p in birds ) [self moveTowards:p->sprite :&beeDestination :p->speed*dt];

Slide 134

Slide 134 text

Kollisjon

Slide 135

Slide 135 text

Kollisjon -(void) beeHitBy:(CCSprite*)bird { CGRect beeBox = [bee boundingBox]; CGRect birdBox = [bird boundingBox]; if ( CGRectIntersectsRect(beeBox, birdBox) ) [self killBee]; }

Slide 136

Slide 136 text

No content

Slide 137

Slide 137 text

No content

Slide 138

Slide 138 text

Oppsummering • iOS • Cocos2D + fysikkmotorer • Spill i Objective-C

Slide 139

Slide 139 text

Takk!