SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
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 Sprite Kit classes
• Implement for iOS
• Implement for Mac
• Add Game Controller support
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
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.
// 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];
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 ∞
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];
SKPhysicsBody
• Object for creating a physics simulation for a node.
• Calculations include gravity, friction, and collisions with other
‘bodies’.
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;
The Update Loop
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
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.
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.
Let’s Walk Through The Code
Game Controller Support
• GameController.framework supported in iOS 7 and OS X Mavericks.
• Standard interface for software and hardware.
Game Controller Types
Gamepad Extended Gamepad
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
}
Game Controller Support
• Two ways to handle input:
• Handle in the update: method of your SKScene
• Register blocks for button press/joystick movement
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)];
}
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;
};
Let’s Walk Through The Code
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
Questions?
Resources
• SpriteKit Programming Guide
• Space Shooter Tutorial at RayWenderlich.com
• iOS Games by Tutorials
• Game code at http://github.com/waynehartman/MadBomber
Experiential Education
• See One
• Do One
• Teach One
@waynehartman

Contenu connexe

Tendances

Starcraft 2 crack
Starcraft 2 crackStarcraft 2 crack
Starcraft 2 cracklizet8575
 
How to build a desktop
How to build a desktopHow to build a desktop
How to build a desktopSam Monga
 
Beck-Phillips_FinalYearProject500894
Beck-Phillips_FinalYearProject500894Beck-Phillips_FinalYearProject500894
Beck-Phillips_FinalYearProject500894Beck Phillips
 
Using Virtual P C 2007
Using  Virtual  P C 2007Using  Virtual  P C 2007
Using Virtual P C 2007Luis Barreto
 
Mobiele Werkplaats Windows 7 deployment met Novell ZCM en ENGL
Mobiele Werkplaats Windows 7 deployment met Novell ZCM en ENGLMobiele Werkplaats Windows 7 deployment met Novell ZCM en ENGL
Mobiele Werkplaats Windows 7 deployment met Novell ZCM en ENGLRoel van Bueren
 
Environment presentation
Environment presentationEnvironment presentation
Environment presentationluisfvazquez1
 

Tendances (9)

Kodu game design
Kodu game designKodu game design
Kodu game design
 
Kodu controls
Kodu controlsKodu controls
Kodu controls
 
Starcraft 2 crack
Starcraft 2 crackStarcraft 2 crack
Starcraft 2 crack
 
How to build a desktop
How to build a desktopHow to build a desktop
How to build a desktop
 
Beck-Phillips_FinalYearProject500894
Beck-Phillips_FinalYearProject500894Beck-Phillips_FinalYearProject500894
Beck-Phillips_FinalYearProject500894
 
Instrucciones
InstruccionesInstrucciones
Instrucciones
 
Using Virtual P C 2007
Using  Virtual  P C 2007Using  Virtual  P C 2007
Using Virtual P C 2007
 
Mobiele Werkplaats Windows 7 deployment met Novell ZCM en ENGL
Mobiele Werkplaats Windows 7 deployment met Novell ZCM en ENGLMobiele Werkplaats Windows 7 deployment met Novell ZCM en ENGL
Mobiele Werkplaats Windows 7 deployment met Novell ZCM en ENGL
 
Environment presentation
Environment presentationEnvironment presentation
Environment presentation
 

Similaire à Get Into Sprite Kit

Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2dVinsol
 
Stefan stolniceanu spritekit, 2 d or not 2d
Stefan stolniceanu   spritekit, 2 d or not 2dStefan stolniceanu   spritekit, 2 d or not 2d
Stefan stolniceanu spritekit, 2 d or not 2dCodecamp Romania
 
Stefan stolniceanu spritekit, 2 d or not 2d
Stefan stolniceanu   spritekit, 2 d or not 2dStefan stolniceanu   spritekit, 2 d or not 2d
Stefan stolniceanu spritekit, 2 d or not 2dCodecamp Romania
 
Bringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo SwitchBringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo SwitchUnity Technologies
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android GamesPlatty Soft
 
Demo creating-physics-game.
Demo creating-physics-game.Demo creating-physics-game.
Demo creating-physics-game.sagaroceanic11
 
My 10 days with Phaser.js - WarsawJS Meetup #13
My 10 days with Phaser.js - WarsawJS Meetup #13My 10 days with Phaser.js - WarsawJS Meetup #13
My 10 days with Phaser.js - WarsawJS Meetup #13Piotr Kowalski
 
BYOD: Build Your First VR Experience with Unreal Engine
BYOD: Build Your First VR Experience with Unreal EngineBYOD: Build Your First VR Experience with Unreal Engine
BYOD: Build Your First VR Experience with Unreal EngineMichael Sheyahshe
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSides Delhi
 
watchOS 2でゲーム作ってみた話
watchOS 2でゲーム作ってみた話watchOS 2でゲーム作ってみた話
watchOS 2でゲーム作ってみた話Kohki Miki
 
Sephy engine development document
Sephy engine development documentSephy engine development document
Sephy engine development documentJaejun Kim
 
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろうUnity Technologies Japan K.K.
 

Similaire à Get Into Sprite Kit (20)

Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014Cocos2d 소개 - Korea Linux Forum 2014
Cocos2d 소개 - Korea Linux Forum 2014
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2d
 
Unity workshop
Unity workshopUnity workshop
Unity workshop
 
Stefan stolniceanu spritekit, 2 d or not 2d
Stefan stolniceanu   spritekit, 2 d or not 2dStefan stolniceanu   spritekit, 2 d or not 2d
Stefan stolniceanu spritekit, 2 d or not 2d
 
Stefan stolniceanu spritekit, 2 d or not 2d
Stefan stolniceanu   spritekit, 2 d or not 2dStefan stolniceanu   spritekit, 2 d or not 2d
Stefan stolniceanu spritekit, 2 d or not 2d
 
Bringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo SwitchBringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android Games
 
Lecture2_practice.pdf
Lecture2_practice.pdfLecture2_practice.pdf
Lecture2_practice.pdf
 
Demo creating-physics-game.
Demo creating-physics-game.Demo creating-physics-game.
Demo creating-physics-game.
 
Basics cocos2d
Basics cocos2dBasics cocos2d
Basics cocos2d
 
My 10 days with Phaser.js - WarsawJS Meetup #13
My 10 days with Phaser.js - WarsawJS Meetup #13My 10 days with Phaser.js - WarsawJS Meetup #13
My 10 days with Phaser.js - WarsawJS Meetup #13
 
BYOD: Build Your First VR Experience with Unreal Engine
BYOD: Build Your First VR Experience with Unreal EngineBYOD: Build Your First VR Experience with Unreal Engine
BYOD: Build Your First VR Experience with Unreal Engine
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOS
 
Soc research
Soc researchSoc research
Soc research
 
Programmers guide
Programmers guideProgrammers guide
Programmers guide
 
watchOS 2でゲーム作ってみた話
watchOS 2でゲーム作ってみた話watchOS 2でゲーム作ってみた話
watchOS 2でゲーム作ってみた話
 
Unity3 d devfest-2014
Unity3 d devfest-2014Unity3 d devfest-2014
Unity3 d devfest-2014
 
Sephy engine development document
Sephy engine development documentSephy engine development document
Sephy engine development document
 
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
 

Dernier

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 

Dernier (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 

Get Into Sprite Kit

  • 1. Get Into Sprite Kit presented by @waynehartman
  • 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. 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
  • 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. 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. 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. SKPhysicsBody • Object for creating a physics simulation for a node. • Calculations include gravity, friction, and collisions with other ‘bodies’.
  • 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;
  • 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. 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. 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.
  • 16. Game Controller Support • GameController.framework supported in iOS 7 and OS X Mavericks. • Standard interface for software and hardware.
  • 17. Game Controller Types Gamepad Extended Gamepad
  • 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. Game Controller Support • Two ways to handle input: • Handle in the update: method of your SKScene • Register blocks for button press/joystick movement
  • 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. 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; };
  • 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
  • 25. Resources • SpriteKit Programming Guide • Space Shooter Tutorial at RayWenderlich.com • iOS Games by Tutorials • Game code at http://github.com/waynehartman/MadBomber
  • 26. Experiential Education • See One • Do One • Teach One