SlideShare a Scribd company logo
1 of 52
Introduction to
SpriteKit
Ștefan Stolniceanu
Background
• More and more game developers emerge, all with common
needs
• Need of fast graphics
• Particles and visual effects
• Physics and animation
• Most of the iconic games are 2D
• Rechanges the focus on developing games instead of
engines
SpriteKit Essentials
• Images of Sprites, Shapes and Particles
• Animations and Physics
• Audio, Video, Visual Effects
• And many other
What SpriteKit has to offer
The Parts of a Sprite Kit Game
Scenes
Actions Physics
Displaying Sprite Kit Content
Application UIView / NSView
SKView skView.presentScene(myScene)
Sprite Kit Nodes
The building blocks of every 2D game
The father, the son, and the holy spirit
SKNode
SKLabelNode
SKEmitterNode
SKShapeNode SKSpriteNode
SKEffectNode
SKScene
SKCropNode
SKNode
var position: CGPoint!
var zRotation: CGFloat!
var xScale: CGFloat!
var yScale: CGFloat!
var alpha: CGFloat!
var hidden: Bool!
SKSpriteNode
• Has an explicit size
• Can display a colour
• Can display a texture
• You can blend the texture with a colour
Your true and only friend
SKSpriteNode
Your true and only friend
SKSpriteNode
• Has an explicit size
• Can display a colour
• Can display a texture
• You can blend the texture with a colour
SKSpriteNode
Your true and only friend
SKSpriteNode
• Has an explicit size
• Can display a colour
• Can display a texture
• You can blend the texture with a colour
SKSpriteNode
Your true and only friend
SKSpriteNode
• Has an explicit size
• Can display a colour
• Can display a texture
• You can blend the texture with a colour
SKTexture
• Represents Sprite Kit bitmap data
• Automatically managed by the framework
SKSpriteNode
Your true and only friend
/* how to create a sprite from a png file */
var sprite = SKSpriteNode()
let texture = SKTexture(imageNamed:”logo”)
sprite.texture = texture
sprite.size = texture.size
VS.
var sprite = SKSpriteNode(imageNamed: “logo”)
SKEmitterNode
That special something something
SKEmitterNode
• Full featured 2D particle system
• Standard startValue and speed
• Advanced keyframe sequence controls
That special something something
SKEmitterNode
That special something something
• Texture
• Scale
• Rotation
• Emission angle
• Emission speed
• Blend modes
SKEmitterNode
That special something something
• Data driven particle effects
• Built-in Xcode editor
• Reduce iteration time
• Empower artists
SKVideoNode
SKVideoNode
–Me
“VideoNode, VideoNode,
VideoNode does whatever a VideoNode does
Can it be less simple?
No, it can’t.
It is a Node, yes it is.
Lookout!
It is the VideoNode!”
SKVideoNode
Video as a first class sprite
• Until now video has been:
• Above your game view
• Below your game view
• Roll your own in OpenGL
• Anywhere else but where you wanted it to be
• Then comes Sprite Kit, making it a first class sprite
SKVideoNode
Video as a first class sprite
• One-line creation
let video = SKVideoNode(videoFileNamed: “video”)
• Built on AVPlayer
SKShapeNode
SKShapeNode
• Dynamic shapes
• Any CGPath
• Built for speed
• Rendered in hardware
• Stroke and/or fill
• Add glow effects
• Multiple subpaths
SKLabelNode
SKLabelNode
• For most text use UIKit/AppKit
• Single line text as a sprite
• Supports all system fonts
• Supports SKActions (of course)
SKEffectNode
SKEffectNode
• Flattens children during render
• shouldEnableEffects
• Group opacity
• Group blend modes
• Optionally apply a CIFilter
• Can cache via shouldRasterize
SKCropNode
SKCropNode
• Mask content of children
• Mask defined as a SKNode
• Transparent area is masked out
• Mask node can have children
• Mask node can run SKActions
Actions and Animation
SKAction
Super simple to use,
It can be compared to a scripting language for SK
Basic SKActions
var action: SKAction!
action = SKAction.rotateByAngle(M_PI, duration: 1.0)
action = SKAction.moveTo(aCGPoint, duration: 1.0)
action = SKAction.fadeAlphaTo(0.75, duration: 1.0)
action = SKAction.scaleBy(2.0, duration: 1.0)
action = SKAction.scaleXBy(1.5, y: 0.5, duration: 1.0)
Running SKActions
It’s alive!
• Actions run immediately
• Copy on add
• Removed on completion
sprite.runAction(SKAction.fadeOutWithDuration:1.0))
Running SKActions,
Running SKActions,
Running SKActions
Running SKActions
• Repeating an action
var dance = SKAction.runBlock(dance)
var danceUntilYouDrop = SKAction.repeatAction(dance, count: 20)
• Repeating an action… forever!
var dance = SKAction.runBlock(dance)
var danceLikeYourLifeDependsOnIt = SKAction.repeatActionForever(dance)
Sequences
Reuse already defined blocks
funkyGuy.runAction(SKAction.sequence([danceSalsa, robotDance, doTheFlop]))
danceSalsa robotDance doTheFlop
SKAction Sequence
Groups
Reuse already defined blocks
crazyGuy.runAction(SKAction.group([danceSalsa, robotDance, doTheFlop]))
danceSalsa
robotDance
doTheFlop
SKAction Group
Sequences… of groups!
Reuse already defined blocks
crazyDrunkGuy.runAction(SKAction.sequence([drinkALot, dance, regret]))
danceSalsa
robotDance
doTheFlop
SKAction Sequences of Groups
let dance = SKAction.group([danceSalsa, robotDance, doTheFlop])
regretdrinkALot
How many, though?
Oh, well…
Built in Physics
Simulation
Physics in Sprite Kit
Truly integrated physics
• Built right into Sprite Kit
• You don’t care about the synchronisation process
• Not a global on/off switch
• Enabled node-by-node
• No performance penalty for what you’re not using
SKPhysicsBody
• Any nodes can have a PhysicsBody
• To do so… whelp… just add one
• You have some of ‘em predefined already
var aPhysicsBody = SKPhysicsBody(rectangleOfSize: 50)
aSprite.physicsBody = aPhysicsBody
SKPhysicsWorld
• Each SKScene has a physicsWorld
• Perform hit tests, ray casts
• Add joints
• Change gravity
//Down!
self.physicsWorld.gravity = CGVector(0.0, -9.8)
//Up!
self.physicsWorld.gravity = CGVector(0.0, 9.8)
PhysicsWorld Contact Delegate
self.physicsWorld.contactDelegate = self
func didBeginContact(contact: SKPhysicsContact) {}
func didEndContact(contact: SKPhysicsContact) {}
SKPhysicsContact
/* the physics bodies involved */
var bodyA: SKPhysicsBody!
var bodyB: SKPhysicsBody!
/* point of first contact */
var contactPoint: CGPoint!
/* magnitude of collision impulse at that point */
var collisionImpulse: CGFloat!
Collision Groups
var categoryBitMask: UInt32!
var collisionBitMask: UInt32!
var contactTestBitMask: UInt32!
Sprite Kit Game Loop
Frames have it rough
Demo

More Related Content

Similar to Stefan stolniceanu spritekit, 2 d or not 2d

iOS 2D Gamedev @ CocoaHeads
iOS 2D Gamedev @ CocoaHeadsiOS 2D Gamedev @ CocoaHeads
iOS 2D Gamedev @ CocoaHeadsAlain Hufkens
 
Creating physics game in 1 hour
Creating physics game in 1 hourCreating physics game in 1 hour
Creating physics game in 1 hourLinkou Bian
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2dVinsol
 
Demo creating-physics-game.
Demo creating-physics-game.Demo creating-physics-game.
Demo creating-physics-game.sagaroceanic11
 
New 2D World-Building, Animation & Graphics Features in Unity
New 2D World-Building, Animation & Graphics Features in UnityNew 2D World-Building, Animation & Graphics Features in Unity
New 2D World-Building, Animation & Graphics Features in UnityUnity Technologies
 
2 Dimensions Of Awesome: Advanced ActionScript For Platform Games by Iain Lobb
2 Dimensions Of Awesome: Advanced ActionScript For Platform Games by Iain Lobb2 Dimensions Of Awesome: Advanced ActionScript For Platform Games by Iain Lobb
2 Dimensions Of Awesome: Advanced ActionScript For Platform Games by Iain Lobbmochimedia
 
Lidnug Presentation - Kinect - The How, Were and When of developing with it
Lidnug Presentation - Kinect - The How, Were and When of developing with itLidnug Presentation - Kinect - The How, Were and When of developing with it
Lidnug Presentation - Kinect - The How, Were and When of developing with itPhilip Wheat
 
Game development via_sprite_kit
Game development via_sprite_kitGame development via_sprite_kit
Game development via_sprite_kitBuşra Deniz, CSM
 
ARTDM 170, Week 14: Organic
ARTDM 170, Week 14: OrganicARTDM 170, Week 14: Organic
ARTDM 170, Week 14: OrganicGilbert Guerrero
 
The not so short
The not so shortThe not so short
The not so shortAXM
 
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
 
iOS Game Development With UIKit
iOS Game Development With UIKitiOS Game Development With UIKit
iOS Game Development With UIKitMartin Grider
 
Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Yuichi Higuchi
 

Similar to Stefan stolniceanu spritekit, 2 d or not 2d (20)

iOS 2D Gamedev @ CocoaHeads
iOS 2D Gamedev @ CocoaHeadsiOS 2D Gamedev @ CocoaHeads
iOS 2D Gamedev @ CocoaHeads
 
Creating physics game in 1 hour
Creating physics game in 1 hourCreating physics game in 1 hour
Creating physics game in 1 hour
 
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
 
Games on AppleWatch
Games on AppleWatchGames on AppleWatch
Games on AppleWatch
 
Demo creating-physics-game.
Demo creating-physics-game.Demo creating-physics-game.
Demo creating-physics-game.
 
New 2D World-Building, Animation & Graphics Features in Unity
New 2D World-Building, Animation & Graphics Features in UnityNew 2D World-Building, Animation & Graphics Features in Unity
New 2D World-Building, Animation & Graphics Features in Unity
 
2 Dimensions Of Awesome: Advanced ActionScript For Platform Games by Iain Lobb
2 Dimensions Of Awesome: Advanced ActionScript For Platform Games by Iain Lobb2 Dimensions Of Awesome: Advanced ActionScript For Platform Games by Iain Lobb
2 Dimensions Of Awesome: Advanced ActionScript For Platform Games by Iain Lobb
 
Lidnug Presentation - Kinect - The How, Were and When of developing with it
Lidnug Presentation - Kinect - The How, Were and When of developing with itLidnug Presentation - Kinect - The How, Were and When of developing with it
Lidnug Presentation - Kinect - The How, Were and When of developing with it
 
Game development via_sprite_kit
Game development via_sprite_kitGame development via_sprite_kit
Game development via_sprite_kit
 
Shootting Game
Shootting GameShootting Game
Shootting Game
 
ARTDM 170, Week 14: Organic
ARTDM 170, Week 14: OrganicARTDM 170, Week 14: Organic
ARTDM 170, Week 14: Organic
 
The not so short
The not so shortThe not so short
The not so short
 
Chapter 12 - Activity Intent
Chapter 12 - Activity  IntentChapter 12 - Activity  Intent
Chapter 12 - Activity Intent
 
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
 
iOS Game Development With UIKit
iOS Game Development With UIKitiOS Game Development With UIKit
iOS Game Development With UIKit
 
Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例Cocos2dを使ったゲーム作成の事例
Cocos2dを使ったゲーム作成の事例
 
Coscup
CoscupCoscup
Coscup
 
XNA in a Day
XNA in a DayXNA in a Day
XNA in a Day
 
Unity workshop
Unity workshopUnity workshop
Unity workshop
 

More from Codecamp Romania

Cezar chitac the edge of experience
Cezar chitac   the edge of experienceCezar chitac   the edge of experience
Cezar chitac the edge of experienceCodecamp Romania
 
Business analysis techniques exercise your 6-pack
Business analysis techniques   exercise your 6-packBusiness analysis techniques   exercise your 6-pack
Business analysis techniques exercise your 6-packCodecamp Romania
 
Bpm company code camp - configuration or coding with pega
Bpm company   code camp - configuration or coding with pegaBpm company   code camp - configuration or coding with pega
Bpm company code camp - configuration or coding with pegaCodecamp Romania
 
Andrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseAndrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseCodecamp Romania
 
2015 dan ardelean develop for windows 10
2015 dan ardelean   develop for windows 10 2015 dan ardelean   develop for windows 10
2015 dan ardelean develop for windows 10 Codecamp Romania
 
The case for continuous delivery
The case for continuous deliveryThe case for continuous delivery
The case for continuous deliveryCodecamp 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
 
Sizing epics tales from an agile kingdom
Sizing epics   tales from an agile kingdomSizing epics   tales from an agile kingdom
Sizing epics tales from an agile kingdomCodecamp Romania
 
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...Codecamp Romania
 
Parallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowParallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowCodecamp Romania
 
Material design screen transitions in android
Material design screen transitions in androidMaterial design screen transitions in android
Material design screen transitions in androidCodecamp Romania
 
Kickstart your own freelancing career
Kickstart your own freelancing careerKickstart your own freelancing career
Kickstart your own freelancing careerCodecamp Romania
 
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu   the soft stuff is the hard stuff. the agile soft skills toolkitIonut grecu   the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkitCodecamp Romania
 
Diana antohi me against myself or how to fail and move forward
Diana antohi   me against myself  or how to fail  and move forwardDiana antohi   me against myself  or how to fail  and move forward
Diana antohi me against myself or how to fail and move forwardCodecamp Romania
 

More from Codecamp Romania (20)

Cezar chitac the edge of experience
Cezar chitac   the edge of experienceCezar chitac   the edge of experience
Cezar chitac the edge of experience
 
Cloud powered search
Cloud powered searchCloud powered search
Cloud powered search
 
Ccp
CcpCcp
Ccp
 
Business analysis techniques exercise your 6-pack
Business analysis techniques   exercise your 6-packBusiness analysis techniques   exercise your 6-pack
Business analysis techniques exercise your 6-pack
 
Bpm company code camp - configuration or coding with pega
Bpm company   code camp - configuration or coding with pegaBpm company   code camp - configuration or coding with pega
Bpm company code camp - configuration or coding with pega
 
Andrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseAndrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabase
 
Agility and life
Agility and lifeAgility and life
Agility and life
 
2015 dan ardelean develop for windows 10
2015 dan ardelean   develop for windows 10 2015 dan ardelean   develop for windows 10
2015 dan ardelean develop for windows 10
 
The bigrewrite
The bigrewriteThe bigrewrite
The bigrewrite
 
The case for continuous delivery
The case for continuous deliveryThe case for continuous delivery
The case for continuous delivery
 
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
 
Sizing epics tales from an agile kingdom
Sizing epics   tales from an agile kingdomSizing epics   tales from an agile kingdom
Sizing epics tales from an agile kingdom
 
Scale net apps in aws
Scale net apps in awsScale net apps in aws
Scale net apps in aws
 
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
 
Parallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowParallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflow
 
Material design screen transitions in android
Material design screen transitions in androidMaterial design screen transitions in android
Material design screen transitions in android
 
Kickstart your own freelancing career
Kickstart your own freelancing careerKickstart your own freelancing career
Kickstart your own freelancing career
 
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu   the soft stuff is the hard stuff. the agile soft skills toolkitIonut grecu   the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
 
Ecma6 in the wild
Ecma6 in the wildEcma6 in the wild
Ecma6 in the wild
 
Diana antohi me against myself or how to fail and move forward
Diana antohi   me against myself  or how to fail  and move forwardDiana antohi   me against myself  or how to fail  and move forward
Diana antohi me against myself or how to fail and move forward
 

Stefan stolniceanu spritekit, 2 d or not 2d

Editor's Notes

  1. ierarhia nodurilor
  2. Tot am Vorbit despre SKActions
  3. One class to rule them all (actions that is) One line creation Chainable, reusable, readable Actions directly affect the node it is run on
  4. Create complex animations Use them for sound effects Run blocks Make your own actions And loads and loads of other actions…
  5. Defines what logical ‘categories’ this body belongs to. Defaults to all bits set (all categories). Defines what logical ‘categories’ this body responds to collisions with. Defaults to all bits set (all categories). Defines what logical ‘categories’ this body generates intersection notifications with. Defaults to all bits cleared (no categories).