Get Into Sprite Kit
presented by @waynehartman
What are we going to learn?
• Basics of Sprite Kit: Main classes for interaction
• Design the game concept and map it to S...
Base Classes
• Content is displayed on an SKView
• Content is organized into instances of SKScene. An SKView only
displays...
Relationship Diagram
SKNodeSKScene
0…*
SKAction
0…*
SKPhysicsBody
0…1
Class Diagram
SKNode
SKScene SKSpriteNode
SKSpriteNode
• SKNode subclass that combines a node with an SKTexture.
• A texture is nothing more than artwork: an image....
SKAction
• Represents actions executed by SKNode instances
• Do things like scale, move position, resize, play sound FX, e...
SKAction
// In SKScene subclass
NSTimeInterval duration = 0.15;
!
SKAction *scale = [SKAction scaleTo:1.5f duration:durati...
SKPhysicsBody
• Object for creating a physics simulation for a node.
• Calculations include gravity, friction, and collisi...
SKPhysicsBody
// Inside SKScene subclass
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
!
SKPhysi...
The Update Loop
The Update Loop
• Performed once per frame
• The bulk of your game logic can be executed in the update: method.
• Player m...
Our Game: Mad Bomber!
• Clone of “Kaboom!”, Atari 2600 game
• The mad bomber drops bombs while
moving back and forth on th...
Turn It Into Code
• We will have one SKView that will display a level
(SKScene).
• An SKLabelNode will be attached to the ...
Let’s Walk Through The Code
Game Controller Support
• GameController.framework supported in iOS 7 and OS X Mavericks.
• Standard interface for softwar...
Game Controller Types
Gamepad Extended Gamepad
Game Controller Discovery
// Somewhere in the initialization of your scene
[[NSNotificationCenter defaultCenter] addObserv...
Game Controller Support
• Two ways to handle input:
• Handle in the update: method of your SKScene
• Register blocks for b...
Game Controller in update:
// In update: method
BOOL leftPressed = _gameController.gamepad.leftShoulder.value > 0.0f;
BOOL...
Game Controller Value Changed Handler
// in a method for setting up the game controller
self.gameController.gamepad.valueC...
Let’s Walk Through The Code
Game Controller Gotchas
• In most cases, make sure to turn off the iOS Idle Timer
!
[[UIApplication sharedApplication] set...
Questions?
Resources
• SpriteKit Programming Guide
• Space Shooter Tutorial at RayWenderlich.com
• iOS Games by Tutorials
• Game code...
Experiential Education
• See One
• Do One
• Teach One
@waynehartman
Upcoming SlideShare
Loading in...5
×

Get Into Sprite Kit

1,131

Published on

Ever wanted to get into making games for iOS or Mac? This session covers the basics you'll need to start doing it!

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,131
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Get Into Sprite Kit

  1. 1. Get Into Sprite Kit presented by @waynehartman
  2. 2. What are we going to learn? • Basics of Sprite Kit: Main classes for interaction • Design the game concept and map it to Sprite Kit classes • Implement for iOS • Implement for Mac • Add Game Controller support
  3. 3. Base Classes • Content is displayed on an SKView • Content is organized into instances of SKScene. An SKView only displays a single SKScene. • A scene has 0…* SKNode objects organized in trees. • Nodes can have SKAction instances added to give on-screen behavior. • Nodes can have SKPhysicsBody instances added for simulating physics interactions
  4. 4. Relationship Diagram SKNodeSKScene 0…* SKAction 0…* SKPhysicsBody 0…1
  5. 5. Class Diagram SKNode SKScene SKSpriteNode
  6. 6. SKSpriteNode • SKNode subclass that combines a node with an SKTexture. • A texture is nothing more than artwork: an image. // Inside SKScene subclass ! SKSpriteNode *ship = [SKSpriteNode spriteNodeWithImageNamed:@“ship.png”]; ship.position = CGPointMake(self.size.width * 0.5f, self.size.height * 0.5f); ! [self addChild:ship];
  7. 7. SKAction • Represents actions executed by SKNode instances • Do things like scale, move position, resize, play sound FX, execute blocks, or just ‘wait’. • Can be strung together in a sequence, or executed simultaneously in a group. • Actions can be repeated 0 to ∞
  8. 8. SKAction // In SKScene subclass NSTimeInterval duration = 0.15; ! SKAction *scale = [SKAction scaleTo:1.5f duration:duration]; SKAction *fade = [SKAction fadeAlphaTo:0.0f duration:duration]; SKAction *fx = [SKAction playSoundFileNamed:@"smallExplosion.caf" waitForCompletion:NO]; SKAction *transform = [SKAction group:@[scale, fade, fx]]; ! SKAction *wait = [SKAction waitForDuration:duration]; ! SKAction *sequence = [SKAction sequence:@[wait, transform]]; ! [bombNode runAction:sequence];
  9. 9. SKPhysicsBody • Object for creating a physics simulation for a node. • Calculations include gravity, friction, and collisions with other ‘bodies’.
  10. 10. SKPhysicsBody // Inside SKScene subclass self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]; ! SKPhysicsBody *physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.player.frame.size]; physicsBody.dynamic = YES; physicsBody.affectedByGravity = NO; physicsBody.mass = 0.01; physicsBody.allowsRotation = NO; ! self.player.physicsBody = physicsBody;
  11. 11. The Update Loop
  12. 12. The Update Loop • Performed once per frame • The bulk of your game logic can be executed in the update: method. • Player movement • Non-physics collision detection • Other condition checks
  13. 13. Our Game: Mad Bomber! • Clone of “Kaboom!”, Atari 2600 game • The mad bomber drops bombs while moving back and forth on the screen. • The player must move on the screen and ‘catch’ the bombs. • The game ends when the player fails to catch a bomb.
  14. 14. Turn It Into Code • We will have one SKView that will display a level (SKScene). • An SKLabelNode will be attached to the screen to display the player’s score. • The Mad Bomber, Player, and bombs will be SKSpriteNode instances. • An SKAction will be added to the Mad Bomber to randomly move him back and forth on the screen. An SKAction will be added to each bomb to move it towards the bottom of the screen. • An SKPhysicsBody will be applied to our scene to act as a ‘collision container’ for our player. • An SKPhysicsBody will be applied to our player to allow it to move back and forth.
  15. 15. Let’s Walk Through The Code
  16. 16. Game Controller Support • GameController.framework supported in iOS 7 and OS X Mavericks. • Standard interface for software and hardware.
  17. 17. Game Controller Types Gamepad Extended Gamepad
  18. 18. Game Controller Discovery // Somewhere in the initialization of your scene [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidConnect:) name:GCControllerDidConnectNotification object:nil]; ! [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidDisconnect:) name:GCControllerDidDisconnectNotification object:nil]; - (void)controllerDidConnect:(NSNotification *)notification { _gameController = notification.object; // Additional controller setup as needed } ! - (void)controllerDidDisconnect:(NSNotification *)notification { _gameController = nil; // Additional controller tear-down as needed }
  19. 19. Game Controller Support • Two ways to handle input: • Handle in the update: method of your SKScene • Register blocks for button press/joystick movement
  20. 20. Game Controller in update: // In update: method BOOL leftPressed = _gameController.gamepad.leftShoulder.value > 0.0f; BOOL rightPressed = _gameController.gamepad.rightShoulder.value > 0.0f; ! if (leftPressed || rightPressed) { float force = 0.0f; ! if (leftPressed){ force = -_gameController.gamepad.leftShoulder.value; } else if (rightPressed) { force = _gameController.gamepad.rightShoulder.value; } ! [self applyPlayerForce:CGVectorMake(20.0f * force, 0.0f)]; }
  21. 21. Game Controller Value Changed Handler // in a method for setting up the game controller self.gameController.gamepad.valueChangedHandler = ^(GCGamepad *gamepad, GCControllerElement *element) { if (gamepad.buttonX == element) { if (gamepad.buttonX.isPressed) { [weakSelf releaseTheKraken]; } } }; ! ! // Or set a handler for the specific button: self.gameController.controllerPausedHandler = ^(GCController *controller) { weakSelf.paused = !weakSelf.paused; };
  22. 22. Let’s Walk Through The Code
  23. 23. Game Controller Gotchas • In most cases, make sure to turn off the iOS Idle Timer ! [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; • Cannot debug while plugged in via Lightning port :( • Your game MUST NOT require the use of a Game Controller • Current generation of hardware kinda sucks • Logitech Powershell and Moga Ace Power
  24. 24. Questions?
  25. 25. Resources • SpriteKit Programming Guide • Space Shooter Tutorial at RayWenderlich.com • iOS Games by Tutorials • Game code at http://github.com/waynehartman/MadBomber
  26. 26. Experiential Education • See One • Do One • Teach One
  27. 27. @waynehartman
  1. Gostou de algum slide específico?

    Recortar slides é uma maneira fácil de colecionar informações para acessar mais tarde.

×