game development via_sprite_kit
TRANSCRIPT
Buşra Deniz
Çanakkale Onsekiz Mart Üniversitesi
Bilgisayar Mühendisliği
Dotto Bilişim Teknolojileri
Mobile Software / Game Developer
Netaş
Mobile Engineer
www.busradeniz.com
[email protected]@busradeniz
Frameworks for game development
OpenGL ES
UIKit controls and views
Third-party libraries (Unity, Unreal 3D, cocos2D, Flash -
as3)
OpenGL ES
Hard to learn
Good for experienced programmer /
company
Cross plotform solutions
Good performance but code complexity
UIKit controls and views
Default iOS programming framework
Buttons, pickers, views, navigation bars etc.
Easy but bad performance
Same interface with other iOS apps
Cons
Locked into iOS ecosystem
No ability to write custom OpenGL
code
Doesn't have as many useful features
as Cocos2D
SKNode properties and methods
Properties position
zposition
xScale - yScale
name
Methods childNodeWithName:(NSString *) name
enumerateChildWithName:usingBlock
Code sample
self.scoreLabel = [[SKLabelNode alloc]
initWithFontNamed:@"Chalkduster"];
self.scoreLabel.fontSize = 15;
self.scoreLabel.color = [UIColor whiteColor];
self.scoreLabel.position = CGPointMake(20, 300);
self.scoreLabel.zPosition = 100;
[self addChild:self.scoreLabel];
SKAction
Move actions
Rotate actions
Actions that change node scale over time
Actions that combine other actions (sequence: / repeatAction:)
Code sample
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
SKAction *moveUp = [SKAction moveBy:CGVectorMake(0, 100)duration:0.8];
SKAction *moveDown = [SKAction moveBy:CGVectorMake(0, -100)duration:0.6];
SKAction *seq = [SKAction sequence:@[moveUp, moveDown]];
Player *player = (Player*)[self childNodeWithName:playerName];[player runAction:seq];
}
Game Interaction
Touching the screen
Gesture recognizers
Accelerometer and gyroscope
Game Controller events
Handling touches
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *) event
Code sample
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];SKSpriteNode *touchedNode = (SKSpriteNode
*)[self nodeAtPoint:[touch locationInNode:self]];
if (touchedNode.name == playerName) {Player *player = (Player*) touchedNode;player.selected = YES;return;
}
}
Gesture Code Sample- (void) handleSwipeRight:(UIGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateRecognized) {
backgroundMoveSpeed += 50;
}
}
- (void) handleSwipeLeft:(UIGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateRecognized &&
backgroundMoveSpeed > 50) {
backgroundMoveSpeed -= 50;
}
}
Code sample
- (void)update:(CFTimeInterval)currentTime{
Insert the following code into it:
[self enumerateChildNodesWithName:@"theLabel" usingBlock:^(SKNode
*node, BOOL *stop) {
node.position = CGPointMake(node.position.x - 2, node.
position.y);
if (node.position.x < - node.frame.size.width) {
node.position = CGPointMake(self.frame.size.width, node.
position.y);
}
}];
}