Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Game development via_sprite_kit

1,000 views

Published on

Game Development via SpriteKit

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Game development via_sprite_kit

  1. 1. Game Development via Sprite Kit BUŞRA DENIZ
  2. 2. 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 busradeniz@outlook.com @busradeniz
  3. 3. Frameworks for game development  OpenGL ES  UIKit controls and views  Third-party libraries (Unity, Unreal 3D, cocos2D, Flash - as3)
  4. 4. OpenGL ES Hard to learn Good for experienced programmer / company Cross plotform solutions Good performance but code complexity
  5. 5. UIKit controls and views Default iOS programming framework Buttons, pickers, views, navigation bars etc. Easy but bad performance Same interface with other iOS apps
  6. 6. Third-party libraries Unity Unreal 3D Cocos 2D (4000+ games) Corona SDK etc.
  7. 7. Cocos2D vs Sprite Kit
  8. 8. What is Sprite Kit ? Apple's 2D game engine for iOS 7
  9. 9. Pros Part of iOS SDK Easy to use API Built-in tools Built-in Physics engine iOS / Mac
  10. 10. Cons Locked into iOS ecosystem No ability to write custom OpenGL code Doesn't have as many useful features as Cocos2D
  11. 11. First Sprite Kit Project
  12. 12. Sprite Kit Basics SKView SKScene SKNode SKAction
  13. 13. SKView
  14. 14. SKScene Only one scene at a time is present on SKView
  15. 15. SKNode  SKNode  SKSpriteNode  SKLabelNode  SKShapeNode  SKEmitterNode  SKEffectNode
  16. 16. SKNode properties and methods Properties  position  zposition  xScale - yScale  name Methods  childNodeWithName:(NSString *) name  enumerateChildWithName:usingBlock
  17. 17. 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];
  18. 18. SKAction Move actions Rotate actions Actions that change node scale over time Actions that combine other actions (sequence: / repeatAction:)
  19. 19. 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]; }
  20. 20. Game Interaction Touching the screen Gesture recognizers Accelerometer and gyroscope Game Controller events
  21. 21. 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
  22. 22. 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; } }
  23. 23. 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; } }
  24. 24. Sprite Kit Run Cycle
  25. 25. 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); } }]; }
  26. 26. Questions ? Thanks...

×