game development via_sprite_kit

26
Game Development via Sprite Kit BUŞRA DENIZ

Upload: busra-deniz-csm

Post on 16-Jul-2015

487 views

Category:

Technology


0 download

TRANSCRIPT

Game

Development via

Sprite KitBUŞRA DENIZ

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

Third-party libraries

Unity

Unreal 3D

Cocos 2D (4000+ games)

Corona SDK etc.

Cocos2D vs Sprite Kit

What is Sprite Kit ?

Apple's 2D game engine for iOS 7

Pros

Part of iOS SDK

Easy to use API

Built-in tools

Built-in Physics engine

iOS / Mac

Cons

Locked into iOS ecosystem

No ability to write custom OpenGL

code

Doesn't have as many useful features

as Cocos2D

First Sprite Kit Project

Sprite Kit Basics

SKView

SKScene

SKNode

SKAction

SKView

SKScene

Only one scene at a time is present on

SKView

SKNode

SKNode

SKSpriteNode

SKLabelNode

SKShapeNode

SKEmitterNode

SKEffectNode

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;

}

}

Sprite Kit Run Cycle

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

}

}];

}

Questions ?

Thanks...