19. SKNode!
The base class!
• Used for grouping in node tree
@property SKNode *parent;
@property SKNode *children;
• Used for positioning itself and children
@property CGPoint position; // relative to parent
@property CGFloat zRotation; // radians
@property CGFloat xScale, yScale; // scaling
• Can control visibility
@property CGFloat alpha;
@property BOOL hidden;
• Can run actions
• Can be a physics body
20. Sprite Kit Nodes!
Node classes
Class Description
SKNode Parent class of all nodes
SKScene Root of the scene graph
SKSpriteNode! Renders a textured sprite
SKEmitterNode Generates and renders particles
SKLabelNode Renders a text string
SKVideoNode Plays video content
SKShapeNode Renders a shape
SKEffectNode Applies a Core Image filter to its children
SKCropNode Crops its children using a mask
29. • Many images combined into a single larger image
• Saves memory
• Improves drawing efficiency
rocket_red.png
rocket_green.png
rocket_flames.png
…
cloud.png
character_1.png
character_2.png
character_3.png
….
Texture Atlases!
Key to performance
30. • Load a SKTexture from a stand-alone file
• Load a SKTexture from a texture atlas
SKTexture *texture = [SKTexture textureWithImageNamed:@“rocket.png"];
SKTexture *texture = [SKTexture textureWithImageNamed:@“rocket.png"];
Texture Atlases!
Loading from a Texture Atlas
It’s the same! Sprite Kit manages atlases for you
33. • Root node of the scene graph
• Displayed by a SKView
• Inherits from SKEffectsNode
• Runs per-frame loop
-update:
-didEvaluateActions
-didSimulatePhysics
SKScene
Background Foreground
HUD
Hero
Score
Bg
Tree
Tree
SKScene!
Presents the content
37. • Very simple to use
• Single action class - SKAction
• One line creation
• Chain-able, reusable, readable
• Like a scripting language for Sprite Kit
• Actions directly affect the node it is run on
• Actions run immediately
• Removed on completion
[node runAction: [SKAction rotateByAngle:M_PI duration:1.0]];
Actions!
43. • Zero duration, fires once
• Show the Game Over menu after character death animation
[SKAction runBlock:^{ doSomething(); }];
SKAction *fade = [SKAction fadeOutWithDuration:1.0];
SKAction *remove = [SKAction removeFromParent];
SKAction *showMenu = [SKAction runBlock:^{ [self showGameOverMenu]; }];
[heroSprite runAction: [SKAction sequence:@[fade, showMenu, remove]] ];
Specialty SKActions!
Run block
47. • Uses Box2D under the hood
• open source physics engine
• C++
• Objective-C API
• Fully integrated into Sprite Kit
Box2D
SpriteKit
Your code
Sprite Kit Physics
48. • Set the physics body of your Sprite
+ =
Physics Body