2. 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
3. SpriteKit Essentials
• Images of Sprites, Shapes and Particles
• Animations and Physics
• Audio, Video, Visual Effects
• And many other
What SpriteKit has to offer
4. The Parts of a Sprite Kit Game
Scenes
Actions Physics
7. The father, the son, and the holy spirit
SKNode
SKLabelNode
SKEmitterNode
SKShapeNode SKSpriteNode
SKEffectNode
SKScene
SKCropNode
8. SKNode
var position: CGPoint!
var zRotation: CGFloat!
var xScale: CGFloat!
var yScale: CGFloat!
var alpha: CGFloat!
var hidden: Bool!
9. 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
10. 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
11. 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
12. 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
14. 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”)
16. SKEmitterNode
• Full featured 2D particle system
• Standard startValue and speed
• Advanced keyframe sequence controls
That special something something
21. 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
22. SKVideoNode
Video as a first class sprite
• One-line creation
let video = SKVideoNode(videoFileNamed: “video”)
• Built on AVPlayer
28. SKEffectNode
• Flattens children during render
• shouldEnableEffects
• Group opacity
• Group blend modes
• Optionally apply a CIFilter
• Can cache via shouldRasterize
30. 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
38. 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)
40. Groups
Reuse already defined blocks
crazyGuy.runAction(SKAction.group([danceSalsa, robotDance, doTheFlop]))
danceSalsa
robotDance
doTheFlop
SKAction Group
41. 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
45. 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
46. 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
47. 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)
49. 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!
One class to rule them all (actions that is)
One line creation
Chainable, reusable, readable
Actions directly affect the node it is run on
Create complex animations
Use them for sound effects
Run blocks
Make your own actions
And loads and loads of other actions…
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).