Slide 1

Slide 1 text

⚒ Tools " Techniques # Teamwork

Slide 2

Slide 2 text

♻ Tweaks & iterations

Slide 3

Slide 3 text

% Smooth, flexible workflows

Slide 4

Slide 4 text

% Smooth, flexible workflows

Slide 5

Slide 5 text

⚒ Tools " Techniques

Slide 6

Slide 6 text

& Scene-based % View-based ' Frame-based

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

SpriteKit Apple’s framework for 2D game development

Slide 11

Slide 11 text

' SKScene

Slide 12

Slide 12 text

( SKSpriteNode ' SKScene

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Hierarchy matching the Sketch file )

Slide 18

Slide 18 text

Hierarchy matching the Sketch file ) * SKTextureAtlas + .spriteatlas

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

, SKAction

Slide 21

Slide 21 text

Jump let jumpAction = SKAction.sequence([ .moveBy(x: 0, y: 3, duration: 0.1), .moveBy(x: 0, y: -3, duration: 0.1) ])

Slide 22

Slide 22 text

Jump let jumpAction = SKAction.sequence([ .moveBy(x: 0, y: 3, duration: 0.1), .moveBy(x: 0, y: -3, duration: 0.1) ]) let carAction = SKAction.sequence([ jumpAction .wait(forDuration: 2) ])

Slide 23

Slide 23 text

Jump let jumpAction = SKAction.sequence([ .moveBy(x: 0, y: 3, duration: 0.1), .moveBy(x: 0, y: -3, duration: 0.1) ]) let carAction = SKAction.sequence([ jumpAction .wait(forDuration: 2) ]) carNode.run(.repeatForever(carAction))

Slide 24

Slide 24 text

Jump let jumpAction = SKAction.sequence([ .moveBy(x: 0, y: 3, duration: 0.1), .moveBy(x: 0, y: -3, duration: 0.1) ]) let wheelAction = SKAction.sequence([ .rotate(byAngle: .pi * 2, duration: 1.5) jumpAction ]) wheelNode.run(.repeatForever(wheelAction)) Rotate & jump let carAction = SKAction.sequence([ jumpAction .wait(forDuration: 2) ]) carNode.run(.repeatForever(carAction))

Slide 25

Slide 25 text

Jump let jumpAction = SKAction.sequence([ .moveBy(x: 0, y: 3, duration: 0.1), .moveBy(x: 0, y: -3, duration: 0.1) ]) let wheelAction = SKAction.sequence([ .rotate(byAngle: .pi * 2, duration: 1.5) jumpAction ]) wheelNode.run(.repeatForever(wheelAction)) Rotate & jump let carAction = SKAction.sequence([ jumpAction .wait(forDuration: 2) ]) carNode.run(.repeatForever(carAction))

Slide 26

Slide 26 text

) Great for complex stand-alone scenes - Easy to compose actions to build animations . Create hierarchies matching the asset structure ♻ Actions can be reused and their parameters can be easily tweaked SpriteKit

Slide 27

Slide 27 text

Button Label ' % View-based animations

Slide 28

Slide 28 text

UIView.animate(withDuration: 0.3) { button.frame.size = CGSize(width: 200, height: 200) } Button

Slide 29

Slide 29 text

UIView.animate(withDuration: 0.3) { button.frame.size = CGSize(width: 200, height: 200) } Button

Slide 30

Slide 30 text

button.alpha = 0 UIView.animate(withDuration: 0.3, animations: { button.alpha = 1 }, completion: { _ in UIView.animate(withDuration: 0.3) { button.frame.size = CGSize(width: 200, height: 200) } })

Slide 31

Slide 31 text

We can do better! /

Slide 32

Slide 32 text

Button Button Button

Slide 33

Slide 33 text

button.animate([ .fadeIn(duration: 0.3), .scale(to: CGSize(width: 200, height: 200), duration: 0.3) ]) Button Button Button

Slide 34

Slide 34 text

struct Animation { var duration: TimeInterval var closure: (UIView) -> Void }

Slide 35

Slide 35 text

struct Animation { var duration: TimeInterval var closure: (UIView) -> Void } extension Animation { } static func fadeIn(duration: TimeInterval) -> Animation { return Animation(duration: duration, closure: { $0.alpha = 1 }) } static func scale(to size: CGSize, duration: TimeInterval) -> Animation { return Animation(duration: duration, closure: { $0.frame.size = size }) }

Slide 36

Slide 36 text

extension UIView { func animate(_ animations: [Animation]) { guard !animations.isEmpty else { return } var animations = animations let animation = animations.removeFirst() UIView.animate(withDuration: animation.duration, animations: { animation.closure(self) }, completion: { _ in self.animate(animations) }) } }

Slide 37

Slide 37 text

extension UIView { func animate(_ animations: [Animation]) { guard !animations.isEmpty else { return } var animations = animations let animation = animations.removeFirst() UIView.animate(withDuration: animation.duration, animations: { animation.closure(self) }, completion: { _ in self.animate(animations) }) } } Exit condition

Slide 38

Slide 38 text

extension UIView { func animate(_ animations: [Animation]) { guard !animations.isEmpty else { return } var animations = animations let animation = animations.removeFirst() UIView.animate(withDuration: animation.duration, animations: { animation.closure(self) }, completion: { _ in self.animate(animations) }) } } Exit condition Take out the next animation

Slide 39

Slide 39 text

extension UIView { func animate(_ animations: [Animation]) { guard !animations.isEmpty else { return } var animations = animations let animation = animations.removeFirst() UIView.animate(withDuration: animation.duration, animations: { animation.closure(self) }, completion: { _ in self.animate(animations) }) } } Exit condition Take out the next animation Perform the animation

Slide 40

Slide 40 text

extension UIView { func animate(_ animations: [Animation]) { guard !animations.isEmpty else { return } var animations = animations let animation = animations.removeFirst() UIView.animate(withDuration: animation.duration, animations: { animation.closure(self) }, completion: { _ in self.animate(animations) }) } } Exit condition Take out the next animation Perform the animation Recursively call the method

Slide 41

Slide 41 text

iHungry 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

Slide 42

Slide 42 text

iHungry 0 1 2 3 4 5 6 7 8 9 : ; < = >

Slide 43

Slide 43 text

burrito.animate([ .scale(to: burrito.frame.size * 1.5, duration: 0.3), .move(to: basket.center, duration: 0.3) ]) iHungry 0 1 2 3 4 5 6 7 8 9 : ; < = >

Slide 44

Slide 44 text

burrito.animate([ .scale(to: burrito.frame.size * 1.5, duration: 0.3), .move(to: basket.center, duration: 0.3) ]) burrito.animate(inParallel: [ .scale(to: burrito.frame.size * 0.5, duration: 0.3), .fadeOut(duration: 0.3) ]) iHungry 0 1 2 3 4 5 6 7 8 9 : ; < = >

Slide 45

Slide 45 text

burrito.animate([ .scale(to: burrito.frame.size * 1.5, duration: 0.3), .move(to: basket.center, duration: 0.3) ]) burrito.animate(inParallel: [ .scale(to: burrito.frame.size * 0.5, duration: 0.3), .fadeOut(duration: 0.3) ]) basket.animate([ .scale(to: basket.frame.size * 1.5, duration: 0.3), .scale(to: basket.frame.size, duration: 0.3) ]) iHungry 0 1 2 3 4 5 6 7 8 9 : ; < = >

Slide 46

Slide 46 text

burrito.animate([ .scale(to: burrito.frame.size * 1.5, duration: 0.3), .move(to: basket.center, duration: 0.3) ]) burrito.animate(inParallel: [ .scale(to: burrito.frame.size * 0.5, duration: 0.3), .fadeOut(duration: 0.3) ]) basket.animate([ .scale(to: basket.frame.size * 1.5, duration: 0.3), .scale(to: basket.frame.size, duration: 0.3) ]) badge.animate(.fadeIn(duration: 0.3)) iHungry 0 1 2 3 4 5 6 7 8 9 : ; < = > 1

Slide 47

Slide 47 text

Demo

Slide 48

Slide 48 text

' Frame-based animations @ & A

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Animation( name: "swordsman-moving-right", frameCount: 8, duration: 1.12 )

Slide 51

Slide 51 text

Animation( name: "swordsman-moving-right", frameCount: 8, duration: 1.12 )

Slide 52

Slide 52 text

Animation( name: "swordsman-moving-right", frameCount: 8, duration: 1.12 ) >100

Slide 57

Slide 57 text

Animation( name: "Swordsman/Right/Moving", frameCount: 8, duration: 1.12 )

Slide 58

Slide 58 text

Animation( name: "Swordsman/Right/Moving", frameCount: 8, duration: 1.12 ) Folder path

Slide 59

Slide 59 text

Animation( name: "Swordsman/Right/Moving", frameCount: 8, duration: 1.12 ) Folder path Number of images

Slide 60

Slide 60 text

Animation( name: "Swordsman/Right/Moving", frameCount: 8, duration: 1.12 ) Folder path Number of images Duration.txt

Slide 61

Slide 61 text

, Script Script

Slide 62

Slide 62 text

, Script Script Characters

Slide 63

Slide 63 text

, Script Script + Folders Characters

Slide 64

Slide 64 text

, Script Script + Folders Characters ⚡ Generate code

Slide 65

Slide 65 text

+ Swordsman/Moving/Right [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] Duration.txt B Animation( name: "Swordsman/Right/Moving", frameCount: , duration: 1.12 ) 8

Slide 66

Slide 66 text

+ Swordsman/Moving/Right [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] Duration.txt B Animation( name: "Swordsman/Right/Moving", frameCount: , duration: 1.12 ) [email protected] 9

Slide 67

Slide 67 text

%

Slide 68

Slide 68 text

% ⚒ Tools

Slide 69

Slide 69 text

% D Organize ⚒ Tools

Slide 70

Slide 70 text

% D Organize B Configs ⚒ Tools

Slide 71

Slide 71 text

% , Scripts D Organize B Configs ⚒ Tools

Slide 72

Slide 72 text

% , Scripts D Organize B Configs ⚒ Tools EF

Slide 73

Slide 73 text

% , Scripts D Organize B Configs ⚒ Tools EF G H

Slide 74

Slide 74 text

% , Scripts D Organize B Configs ⚒ Tools E F G H

Slide 75

Slide 75 text

@johnsundell