192
© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Graphics and Games #WWDC16 Session 610 What’s New in SpriteKit Ross Dexter Games Technologies Engineer Clément Boissière Games Technologies Engineer

What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

  • Upload
    others

  • View
    21

  • Download
    0

Embed Size (px)

Citation preview

Page 1: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Graphics and Games #WWDC16

Session 610

What’s New in SpriteKit

Ross Dexter Games Technologies EngineerClément Boissière Games Technologies Engineer

Page 2: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

What Is SpriteKit?

Page 3: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Framework featuresWhat Is SpriteKit?

2D graphics framework for gamesFlexible, easy to use, high-performanceSupported on iOS, macOS, tvOS & watchOS Automatic access to the latest updatesNatural integration with Swift

Page 4: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Xcode-integrated live editorWhat Is SpriteKit?

Visually lay out your game scenesTimeline-based animationParticle editorAsset Catalog integrationTile map editingGameplayKit integration

Page 5: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Built-in Metal supportWhat Is SpriteKit?

Automatically Metal-backedZero action required for developers

Page 6: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 7: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Scene Outline View

Page 8: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Scene hierarchy at-a-glanceScene Outline View

The Jump Bar contains the scene hierarchy• Only allows for selection• Shows one branch at a time

Page 9: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Scene hierarchy at-a-glanceScene Outline View

Scene Outline View shows the entire hierarchy• Select, rename, remove• Drag to parent/unparent• Can lock and/or hide nodes

NEW

Page 10: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

GameplayKit Integration

Page 11: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Entities and componentsGameplayKit Integration

Design pattern focused on modularityComponents encapsulate behavior• Health• Collision• Player input

Write it once, assign to multiple objects

Page 12: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Entities and componentsGameplayKit Integration NEW

Assign components directly from the editorProperties can be tweaked via the inspectorWe take care of the hard stuff for you

Page 13: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

PathfindingGameplayKit Integration

Pathfinding uses navigation graphsGraphs are collections of nodesNodes are joined by connectionsDescribes how to move through scene

Page 14: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Navigation graph editorGameplayKit Integration

Create and edit navigation graphs• Add and remove nodes• Create or adjust connections

NEW

Page 15: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

FPS Performance Gauge

Page 16: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Real-time performance breakdownFPS Performance Gauge

Page 17: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Real-time performance breakdownFPS Performance Gauge

Frame rate

Page 18: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Real-time performance breakdownFPS Performance Gauge

Frame rateGPU utilization

Page 19: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Real-time performance breakdownFPS Performance Gauge

Frame rateGPU utilizationCPU/GPU frame time

Page 20: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Real-time performance breakdownFPS Performance Gauge

Frame rateGPU utilizationCPU/GPU frame time

Page 21: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Real-time performance breakdownFPS Performance Gauge

Breakdown of update loop• Render• Client update• Actions• Physics

Easy to identify bottlenecksAvailable on iOS and watchOS

NEW

Page 22: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Real-time performance breakdownFPS Performance Gauge

Breakdown of update loop• Render• Client update• Actions• Physics

Easy to identify bottlenecksAvailable on iOS and watchOS

NEW

Page 23: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Real-time performance breakdownFPS Performance Gauge

Breakdown of update loop• Render• Client update• Actions• Physics

Easy to identify bottlenecksAvailable on iOS and watchOS

NEW

Page 24: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Tile Maps

Page 25: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

NEW

What are tile maps?Tile Maps

Tile maps are a grid of evenly spaced imagesUsed to build scenes from repeating imagesQuickly create large, detailed scenes

Page 26: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

NEW

What are tile maps?Tile Maps

Tile maps are a grid of evenly spaced imagesUsed to build scenes from repeating imagesQuickly create large, detailed scenes

Page 27: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

NEW

What are tile maps?Tile Maps

Tile maps are a grid of evenly spaced imagesUsed to build scenes from repeating imagesQuickly create large, detailed scenes

Page 28: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Could place individual images by handPros• Small images help keep overhead low• Can be rearranged

Cons• Tedious and time consuming• Clutters the scene with lots of nodes• Quickly becomes difficult to manage

Page 29: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Could place individual images by handPros• Small images help keep overhead low• Can be rearranged

Cons• Tedious and time consuming• Clutters the scene with lots of nodes• Quickly becomes difficult to manage

Page 30: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Could use static images for your scenesPros• Easy to place and manage• Doesn’t clutter the scene

Cons• Tweaks require changing your assets• Large images require more memory• Variety requires additional large assets

Page 31: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Tile maps get you the best of both solutions• Easy to manage• Can be quickly modified• Large scenes with low overhead

NEW

Page 32: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Tile maps get you the best of both solutions• Easy to manage• Can be quickly modified• Large scenes with low overhead

NEW

Page 33: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Great for lots of different games and art styles

NEW

Page 34: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Great for lots of different games and art styles• Top-down RPGs

NEW

Page 35: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Great for lots of different games and art styles• Top-down RPGs• Side-scrolling platformers

NEW

Page 36: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Great for lots of different games and art styles• Top-down RPGs• Side-scrolling platformers• Isometric city builders

NEW

Page 37: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Why use tile maps?Tile Maps

Great for lots of different games and art styles• Top-down RPGs• Side-scrolling platformers• Isometric city builders• Hex-based board games

NEW

Page 38: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

DemoTile maps in action

Page 39: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Class overviewTile Maps

SKTileMapNode

SKTileSet

SKTileGroup

SKTileGroupRule

SKTileDefinition

NEW

SKTileMapNode is the tile mapDerived from SKNodeContains all of the placed tiles Needs a tile set to be able to place tiles

Page 40: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Class overviewTile Maps NEW

SKTileSet contains all placeable tile groupsAlso defines the type of tiles it contains• Grid• Isometric• Hexagonal

SKTileMapNode

SKTileSet

SKTileGroup

SKTileGroupRule

SKTileDefinition

Page 41: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Class overviewTile Maps

SKTileGroup contains a set of related tiles• Grass• Water• Stone

Has rules that govern tile placement

NEW

SKTileMapNode

SKTileSet

SKTileGroup

SKTileGroupRule

SKTileDefinition

Page 42: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Class overviewTile Maps NEW

SKTileMapNode

SKTileSet

SKTileGroup

SKTileGroupRule

SKTileDefinition

SKTileGroupRule controls how to interactContains tile variants

Page 43: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Class overviewTile Maps

SKTileMapNode

SKTileSet

SKTileGroup

SKTileGroupRule

SKTileDefinition

NEW

SKTileDefinition defines tile appearanceAllows for animationImages can be flipped and/or rotated

Page 44: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 45: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 46: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 47: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 48: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 49: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 50: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 51: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 52: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 53: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 54: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Creating Tile Maps and Setting Tiles

// Get the tile set

guard let tileSet = SKTileSet(named: ”MyTileSet”) else { return }

// Create a tile map

let tileSize = CGSize(width: 32.0, height: 32.0)

let tileMap = SKTileMapNode(tileSet: tileSet, columns: 16, rows: 16, tileSize: tileSize)

// Get a tile group from the tile set

let tileGroup = tileSet.tileGroups.first

// Set tile group for a specific tile

tileMap.setTileGroup(tileGroup, forColumn: 4, row: 7)

// Fill the entire map with a tile group

tileMap.fill(with: tileGroup)

Page 55: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Check user data in the tile under the player’s sprite

// Convert the player’s position into the tile map’s frame of reference

let position = tileMap.convert(playerSprite.position, from: playerSprite)

// Get the column and row of the tile that contains the position

let column = tileMap.tileColumnIndex(fromPosition: position)

let row = tileMap.tileRowIndex(fromPosition: position)

// Get the tile definition in the tile the player’s sprite is over

guard let definition = tileMap.tileDefinition(atColumn: column, row: row) else { return }

// Access custom user data on the tile definition

let customUserData = definition.userData?.value(forKey: “MyKey”)

Page 56: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Check user data in the tile under the player’s sprite

// Convert the player’s position into the tile map’s frame of reference

let position = tileMap.convert(playerSprite.position, from: playerSprite)

// Get the column and row of the tile that contains the position

let column = tileMap.tileColumnIndex(fromPosition: position)

let row = tileMap.tileRowIndex(fromPosition: position)

// Get the tile definition in the tile the player’s sprite is over

guard let definition = tileMap.tileDefinition(atColumn: column, row: row) else { return }

// Access custom user data on the tile definition

let customUserData = definition.userData?.value(forKey: “MyKey”)

Page 57: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Check user data in the tile under the player’s sprite

// Convert the player’s position into the tile map’s frame of reference

let position = tileMap.convert(playerSprite.position, from: playerSprite)

// Get the column and row of the tile that contains the position

let column = tileMap.tileColumnIndex(fromPosition: position)

let row = tileMap.tileRowIndex(fromPosition: position)

// Get the tile definition in the tile the player’s sprite is over

guard let definition = tileMap.tileDefinition(atColumn: column, row: row) else { return }

// Access custom user data on the tile definition

let customUserData = definition.userData?.value(forKey: “MyKey”)

Page 58: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Check user data in the tile under the player’s sprite

// Convert the player’s position into the tile map’s frame of reference

let position = tileMap.convert(playerSprite.position, from: playerSprite)

// Get the column and row of the tile that contains the position

let column = tileMap.tileColumnIndex(fromPosition: position)

let row = tileMap.tileRowIndex(fromPosition: position)

// Get the tile definition in the tile the player’s sprite is over

guard let definition = tileMap.tileDefinition(atColumn: column, row: row) else { return }

// Access custom user data on the tile definition

let customUserData = definition.userData?.value(forKey: “MyKey”)

Page 59: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Check user data in the tile under the player’s sprite

// Convert the player’s position into the tile map’s frame of reference

let position = tileMap.convert(playerSprite.position, from: playerSprite)

// Get the column and row of the tile that contains the position

let column = tileMap.tileColumnIndex(fromPosition: position)

let row = tileMap.tileRowIndex(fromPosition: position)

// Get the tile definition in the tile the player’s sprite is over

guard let definition = tileMap.tileDefinition(atColumn: column, row: row) else { return }

// Access custom user data on the tile definition

let customUserData = definition.userData?.value(forKey: “MyKey”)

Page 60: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Check user data in the tile under the player’s sprite

// Convert the player’s position into the tile map’s frame of reference

let position = tileMap.convert(playerSprite.position, from: playerSprite)

// Get the column and row of the tile that contains the position

let column = tileMap.tileColumnIndex(fromPosition: position)

let row = tileMap.tileRowIndex(fromPosition: position)

// Get the tile definition in the tile the player’s sprite is over

guard let definition = tileMap.tileDefinition(atColumn: column, row: row) else { return }

// Access custom user data on the tile definition

let customUserData = definition.userData?.value(forKey: “MyKey”)

Page 61: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Check user data in the tile under the player’s sprite

// Convert the player’s position into the tile map’s frame of reference

let position = tileMap.convert(playerSprite.position, from: playerSprite)

// Get the column and row of the tile that contains the position

let column = tileMap.tileColumnIndex(fromPosition: position)

let row = tileMap.tileRowIndex(fromPosition: position)

// Get the tile definition in the tile the player’s sprite is over

guard let definition = tileMap.tileDefinition(atColumn: column, row: row) else { return }

// Access custom user data on the tile definition

let customUserData = definition.userData?.value(forKey: “MyKey”)

Page 62: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Check user data in the tile under the player’s sprite

// Convert the player’s position into the tile map’s frame of reference

let position = tileMap.convert(playerSprite.position, from: playerSprite)

// Get the column and row of the tile that contains the position

let column = tileMap.tileColumnIndex(fromPosition: position)

let row = tileMap.tileRowIndex(fromPosition: position)

// Get the tile definition in the tile the player’s sprite is over

guard let definition = tileMap.tileDefinition(atColumn: column, row: row) else { return }

// Access custom user data on the tile definition

let customUserData = definition.userData?.value(forKey: “MyKey”)

Page 63: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Check user data in the tile under the player’s sprite

// Convert the player’s position into the tile map’s frame of reference

let position = tileMap.convert(playerSprite.position, from: playerSprite)

// Get the column and row of the tile that contains the position

let column = tileMap.tileColumnIndex(fromPosition: position)

let row = tileMap.tileRowIndex(fromPosition: position)

// Get the tile definition in the tile the player’s sprite is over

guard let definition = tileMap.tileDefinition(atColumn: column, row: row) else { return }

// Access custom user data on the tile definition

let customUserData = definition.userData?.value(forKey: “MyKey”)

Page 64: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Framework feature recapTile Maps

Tile maps get more out of your art budget• Fewer assets needed• Reduced memory overhead

Supports animation

NEW

Page 65: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Framework feature recapTile Maps

Designed to be layered• Increased asset versatility• Enables effects

Great for different art styles and games

NEW

Page 66: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Framework feature recapTile Maps NEW

Automatic subdivision• Only visible chunks are drawn

Batch renderingMultiple tile types• Grid• Isometric• Hexagonal

Page 67: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Editor feature recapTile Maps

Editing tile maps is simple and easyAutomapping does the hard work for youCreate new tile sets visually

NEW

Page 68: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Warp Transformation

Clément Boissière Games Technologies Engineer

Page 69: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionWarp Transformation

Page 70: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionWarp Transformation

Available transforms in SpriteKit

Page 71: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionWarp Transformation

Available transforms in SpriteKit• Scale

Page 72: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionWarp Transformation

Available transforms in SpriteKit• Scale• Rotation

Page 73: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionWarp Transformation

Available transforms in SpriteKit• Scale• Rotation• Custom shader

Page 74: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionWarp Transformation

SKWarpGeometry• Two grids of points defining the distortion• Source positions• Destination positions

NEW

Page 75: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionWarp Transformation

SKWarpGeometry• Two grids of points defining the distortion• Source positions• Destination positions

NEW

Page 76: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionWarp Transformation

SKWarpGeometry• Two grids of points defining the distortion• Source positions• Destination positions

NEW

Page 77: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionWarp Transformation

SKWarpGeometry• Two grids of points defining the distortion• Source positions• Destination positions

NEW

Page 78: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplesWarp Transformation NEW

Page 79: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplesWarp Transformation

A few examples

NEW

Page 80: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplesWarp Transformation

A few examples• Squash

NEW

Page 81: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplesWarp Transformation

A few examples• Squash• Stretch

NEW

Page 82: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplesWarp Transformation

A few examples• Squash• Stretch• Keyframe-based animations

NEW

Page 83: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation NEW

Page 84: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

Concept• A grid is an indexed set of points

NEW

0 1 2

3 4 5

6 7 8

Page 85: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

Concept• A grid is an indexed set of points• Each cell is a quad

NEW

0 1 2

3 4 5

6 7 8

Page 86: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

Concept• A grid is an indexed set of points• Each cell is a quad• Vertices change to create distortion

NEW

0 1 2

3 4 5

6 7 8

Page 87: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

Concept• A grid is an indexed set of points• Each cell is a quad• Vertices change to create distortion• Keep the same texture coordinates

NEW

0 1 2

3 4 5

6 7 8

Page 88: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

Concept• A grid is an indexed set of points• Each cell is a quad• Vertices change to create distortion• Keep the same texture coordinates• GPU interpolation

NEW

0 1 2

3 4 5

6 7 8

Page 89: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

Concept• A grid is an indexed set of points• Each cell is a quad• Vertices change to create distortion• Keep the same texture coordinates• GPU interpolation

NEW

Page 90: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Warp Transformation NEW

Page 91: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Warp Transformation NEW

Page 92: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

Higher level of details• More cells?

NEW

Page 93: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

Higher level of details• More cells?

NEW

Page 94: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation NEW

Page 95: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

End result• Automatic quad subdivisions• High level of detail• Minimal quad count

NEW

Page 96: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

How it worksWarp Transformation

You can specify the max subdivision level• Adjust details level• Performance tuning

NEW

sd = 1 sd = 4

Page 97: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// SKWarpGeometryGrid - 2x2 grid example.

// [0]---[1]---[2]

// | | |

// [3]---[4]---[5]

// | | |

// [6]---[7]---[8]

var src = [float2]()

var dst = [float2]()

let warpGrid = SKWarpGeometryGrid(columns: 2,

rows: 2,

sourcePositions: src,

destPositions: dst)

sprite.warpGeometry = warpGrid

sprite.subdivisionLevels = 3 // Optional, defaults to 2

NEW

Page 98: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// SKWarpGeometryGrid - 2x2 grid example.

// [0]---[1]---[2]

// | | |

// [3]---[4]---[5]

// | | |

// [6]---[7]---[8]

var src = [float2]()

var dst = [float2]()

let warpGrid = SKWarpGeometryGrid(columns: 2,

rows: 2,

sourcePositions: src,

destPositions: dst)

sprite.warpGeometry = warpGrid

sprite.subdivisionLevels = 3 // Optional, defaults to 2

NEW

Page 99: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// SKWarpGeometryGrid - 2x2 grid example.

// [0]---[1]---[2]

// | | |

// [3]---[4]---[5]

// | | |

// [6]---[7]---[8]

var src = [float2]()

var dst = [float2]()

let warpGrid = SKWarpGeometryGrid(columns: 2,

rows: 2,

sourcePositions: src,

destPositions: dst)

sprite.warpGeometry = warpGrid

sprite.subdivisionLevels = 3 // Optional, defaults to 2

NEW

Page 100: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// SKWarpGeometryGrid - 2x2 grid example.

// [0]---[1]---[2]

// | | |

// [3]---[4]---[5]

// | | |

// [6]---[7]---[8]

var src = [float2]()

var dst = [float2]()

let warpGrid = SKWarpGeometryGrid(columns: 2,

rows: 2,

sourcePositions: src,

destPositions: dst)

sprite.warpGeometry = warpGrid

sprite.subdivisionLevels = 3 // Optional, defaults to 2

NEW

Page 101: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// SKWarpGeometryGrid - 2x2 grid example.

// [0]---[1]---[2]

// | | |

// [3]---[4]---[5]

// | | |

// [6]---[7]---[8]

var src = [float2]()

var dst = [float2]()

let warpGrid = SKWarpGeometryGrid(columns: 2,

rows: 2,

sourcePositions: src,

destPositions: dst)

sprite.warpGeometry = warpGrid

sprite.subdivisionLevels = 3 // Optional, defaults to 2

NEW

Page 102: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// New SKAction

let a1 = SKAction.warp(to: grid,

duration: 5.0)

let a2 = SKAction.animate(withWarps: [grid1, grid2, grid3],

times: [t1, t2, t3])

let a3 = SKAction.animate(withWarps: [grid1, grid2, grid3],

times: [t1, t2, t3],

restore: true)

NEW

Page 103: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// New SKAction

let a1 = SKAction.warp(to: grid,

duration: 5.0)

let a2 = SKAction.animate(withWarps: [grid1, grid2, grid3],

times: [t1, t2, t3])

let a3 = SKAction.animate(withWarps: [grid1, grid2, grid3],

times: [t1, t2, t3],

restore: true)

NEW

Page 104: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// New SKAction

let a1 = SKAction.warp(to: grid,

duration: 5.0)

let a2 = SKAction.animate(withWarps: [grid1, grid2, grid3],

times: [t1, t2, t3])

let a3 = SKAction.animate(withWarps: [grid1, grid2, grid3],

times: [t1, t2, t3],

restore: true)

NEW

Page 105: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

DemoWarp transformation

Page 106: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Per-Node Attributes for Custom Shaders

Page 107: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionPer-Node Attributes for Custom Shaders

Custom shaders in SpriteKit• SKShader (fragment shader)• Built-in shader symbols• SKUniform

Page 108: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Game ideaPer-Node Attributes for Custom Shaders

Page 109: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Game ideaPer-Node Attributes for Custom Shaders

Page 110: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Game ideaPer-Node Attributes for Custom Shaders

Page 111: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Game ideaPer-Node Attributes for Custom Shaders

Page 112: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Game ideaPer-Node Attributes for Custom Shaders

Page 113: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplePer-Node Attributes for Custom Shaders

Shader UniformSprite

u_health

Page 114: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplePer-Node Attributes for Custom Shaders

u_health : float

low

0.2

half

0.5

full

1.0

Page 115: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplePer-Node Attributes for Custom Shaders

Shader1Sprite1 Uniform0.5

u_health

Page 116: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplePer-Node Attributes for Custom Shaders

Shader1Sprite1 Uniform0.50.5

u_health

Page 117: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

u_health

u_health

ExamplePer-Node Attributes for Custom Shaders

Shader2 UniformSprite20.2

Shader3 UniformSprite31.0

Shader1Sprite1 Uniform0.50.5

u_health

Page 118: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

u_health

u_health

ExamplePer-Node Attributes for Custom Shaders

Shader2 UniformSprite20.2

Shader3 UniformSprite31.0

Shader1Sprite1 Uniform0.50.5

u_health

Page 119: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

ExamplePer-Node Attributes for Custom Shaders

Shader

Sprite1

Sprite2

Sprite3

Page 120: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

a_health

a_health

a_health

a_health

Attribute

ExamplePer-Node Attributes for Custom Shaders

Shader

NEW

Sprite1

Sprite2

Sprite3

0.5

0.2

1.0

Page 121: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// SKAttribute for Per-Node Customization

// 1) Create your attributes:

let attribute = SKAttribute(name: "a_health", type: .float)

// 2) Attach to a shader:

shader.attributes = [attribute]

// 3) Set attributes directly on compatible nodes:

sprite1.setValue(SKAttributeValue(float: 0.2), forAttributeNamed: "a_health")

sprite2.setValue(SKAttributeValue(float: 0.5), forAttributeNamed: "a_health")

sprite3.setValue(SKAttributeValue(float: 1.0), forAttributeNamed: "a_health")

Page 122: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// SKAttribute for Per-Node Customization

// 1) Create your attributes:

let attribute = SKAttribute(name: "a_health", type: .float)

// 2) Attach to a shader:

shader.attributes = [attribute]

// 3) Set attributes directly on compatible nodes:

sprite1.setValue(SKAttributeValue(float: 0.2), forAttributeNamed: "a_health")

sprite2.setValue(SKAttributeValue(float: 0.5), forAttributeNamed: "a_health")

sprite3.setValue(SKAttributeValue(float: 1.0), forAttributeNamed: "a_health")

NEW

Page 123: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// SKAttribute for Per-Node Customization

// 1) Create your attributes:

let attribute = SKAttribute(name: "a_health", type: .float)

// 2) Attach to a shader:

shader.attributes = [attribute]

// 3) Set attributes directly on compatible nodes:

sprite1.setValue(SKAttributeValue(float: 0.2), forAttributeNamed: "a_health")

sprite2.setValue(SKAttributeValue(float: 0.5), forAttributeNamed: "a_health")

sprite3.setValue(SKAttributeValue(float: 1.0), forAttributeNamed: "a_health")

NEW

Page 124: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// SKAttribute for Per-Node Customization

// 1) Create your attributes:

let attribute = SKAttribute(name: "a_health", type: .float)

// 2) Attach to a shader:

shader.attributes = [attribute]

// 3) Set attributes directly on compatible nodes:

sprite1.setValue(SKAttributeValue(float: 0.2), forAttributeNamed: "a_health")

sprite2.setValue(SKAttributeValue(float: 0.5), forAttributeNamed: "a_health")

sprite3.setValue(SKAttributeValue(float: 1.0), forAttributeNamed: "a_health")

NEW

Page 125: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Focus Interaction on Apple TV

Page 126: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionFocus Interaction on Apple TV

Page 127: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionFocus Interaction on Apple TV

Interaction on tvOS• Integrated with UIKit• Simple to use• Consistent user experience• Support a wide range of controllers

Page 128: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

SpriteKit integrationFocus Interaction on Apple TV

Now also integrated with SpriteKit!Use cases• Game menus• Entire game interaction• Less code!

NEW

Page 129: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Focus extended support for non-view items

public protocol UIFocusItem : UIFocusEnvironment NEW

Page 130: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// Focus extended support for non-view items

public protocol UIFocusItem : UIFocusEnvironment

// SKNode now conforms to the UIFocusItem protocol

public class SKNode : UIResponder, NSCopying, NSCoding,

NEW

UIFocusItem

Page 131: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// 1) Create a subclass

class MenuElementNode : SKSpriteNode {

// 2) Override canBecomeFocused

override func canBecomeFocused() -> Bool {

return true

}

}

NEW

Page 132: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// 1) Create a subclass

class MenuElementNode : SKSpriteNode {

// 2) Override canBecomeFocused

override func canBecomeFocused() -> Bool {

return true

}

}

NEW

Page 133: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

// 1) Create a subclass

class MenuElementNode : SKSpriteNode {

// 2) Override canBecomeFocused

override func canBecomeFocused() -> Bool {

return true

}

}

NEW

Page 134: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

NEWclass GameScene : SKScene {

let menuItem = MenuElementNode()

override func sceneDidLoad() { // 3) Opt-in the node for focus interaction self.menuItem.isUserInteractionEnabled = true; }

// 4) Track focus updates on your SKView, SKScene // or any SKNode that would make sense for your app logic. override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) { let prevItem = context.previouslyFocusedItem let nextItem = context.nextFocusedItem

if nextItem is MenuElementNode { // Run some SKAction } } }

Page 135: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

NEWclass GameScene : SKScene {

let menuItem = MenuElementNode()

override func sceneDidLoad() { // 3) Opt-in the node for focus interaction self.menuItem.isUserInteractionEnabled = true; }

// 4) Track focus updates on your SKView, SKScene // or any SKNode that would make sense for your app logic. override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) { let prevItem = context.previouslyFocusedItem let nextItem = context.nextFocusedItem

if nextItem is MenuElementNode { // Run some SKAction } } }

Page 136: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

NEWclass GameScene : SKScene {

let menuItem = MenuElementNode()

override func sceneDidLoad() { // 3) Opt-in the node for focus interaction self.menuItem.isUserInteractionEnabled = true; }

// 4) Track focus updates on your SKView, SKScene // or any SKNode that would make sense for your app logic. override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) { let prevItem = context.previouslyFocusedItem let nextItem = context.nextFocusedItem

if nextItem is MenuElementNode { // Run some SKAction } } }

Page 137: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

SpriteKit integrationFocus Interaction on Apple TV NEW

Page 138: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

SpriteKit on Apple Watch

Page 139: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionSpriteKit on Apple Watch

SpriteKit now available for Apple Watch!• High-performance 2D graphics framework• Particles, actions, physics, animations• Scene and Particle Editors• Debugging tools

NEW

Page 140: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

IntroductionSpriteKit on Apple Watch

SpriteKit now available for Apple Watch!• High-performance 2D graphics framework• Particles, actions, physics, animations• Scene and Particle Editors• Debugging tools

NEW

Page 141: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Getting startedSpriteKit on Apple Watch

SKView

Page 142: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Getting startedSpriteKit on Apple Watch

SKView

SKScene

Page 143: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Getting startedSpriteKit on Apple Watch

SKSpriteNode

SKLabelNode

SKEmitterNode

SKCropNode

SKShapeNode

SKTileMapNode

SKFieldNode

SKCameraNode

SKLightNode

SKView

SKScene

Page 144: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Getting startedSpriteKit on Apple Watch

SKSpriteNode

SKLabelNode

SKEmitterNode

SKCropNode

SKShapeNode

SKTileMapNode

SKFieldNode

SKCameraNode

SKLightNode

SKScene

WKInterfaceSKScene

Page 145: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 146: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 147: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 148: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 149: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 150: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 151: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 152: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 153: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 154: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 155: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 156: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 157: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,
Page 158: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

CompatibilitySpriteKit on Apple Watch

Audio playback SKAudioNode not supported SKAction playSoundFileNamed

Video playback SKVideoNode not supported WKInterfaceMovie

Visual effectsSKEffectNode using CoreImage Filter SKEffectNode using SKShader

NEW

Page 159: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

CompatibilitySpriteKit on Apple Watch

Audio playback SKAudioNode not supported SKAction playSoundFileNamed

Video playback SKVideoNode not supported WKInterfaceMovie

Visual effectsSKEffectNode using CoreImage Filter SKEffectNode using SKShader

NEW

Page 160: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

CompatibilitySpriteKit on Apple Watch

Audio playback SKAudioNode not supported SKAction playSoundFileNamed

Video playback SKVideoNode not supported WKInterfaceMovie

Visual effectsSKEffectNode using CoreImage Filter SKEffectNode using SKShader

NEW

Page 161: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

CompatibilitySpriteKit on Apple Watch

Audio playback SKAudioNode not supported SKAction playSoundFileNamed

Video playback SKVideoNode not supported WKInterfaceMovie

Visual effectsSKEffectNode using CoreImage Filter SKEffectNode using SKShader

NEW

Page 162: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

CompatibilitySpriteKit on Apple Watch

Audio playback SKAudioNode not supported SKAction playSoundFileNamed

Video playback SKVideoNode not supported WKInterfaceMovie

Visual effectsSKEffectNode using CoreImage Filter SKEffectNode using SKShader

NEW

Page 163: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

CompatibilitySpriteKit on Apple Watch

Audio playback SKAudioNode not supported SKAction playSoundFileNamed

Video playback SKVideoNode not supported WKInterfaceMovie

Visual effectsSKEffectNode using CoreImage Filter SKEffectNode using SKShader

NEW

Page 164: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

CompatibilitySpriteKit on Apple Watch

Audio playback SKAudioNode not supported SKAction playSoundFileNamed

Video playback SKVideoNode not supported WKInterfaceMovie

Visual effectsSKEffectNode using CoreImage Filter SKEffectNode using SKShader

NEW

Page 165: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

SpriteKit Best Practices

Page 166: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Asset CatalogSpriteKit Tips & Tricks

Page 167: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Asset CatalogSpriteKit Tips & Tricks

SpriteKit is fully integrated with Asset Catalog

Page 168: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Asset CatalogSpriteKit Tips & Tricks

SpriteKit is fully integrated with Asset Catalog• Use sprite atlas for minimal draw calls

Page 169: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Asset CatalogSpriteKit Tips & Tricks

SpriteKit is fully integrated with Asset Catalog• Use sprite atlas for minimal draw calls• Support assets of multiple size (1x, 2x, 3x)

Page 170: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Asset CatalogSpriteKit Tips & Tricks

SpriteKit is fully integrated with Asset Catalog• Use sprite atlas for minimal draw calls• Support assets of multiple size (1x, 2x, 3x)• Support for On-Demand Resources (iOS, tvOS)

Page 171: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Asset CatalogSpriteKit Tips & Tricks

SpriteKit is fully integrated with Asset Catalog• Use sprite atlas for minimal draw calls• Support assets of multiple size (1x, 2x, 3x)• Support for On-Demand Resources (iOS, tvOS)• Compiles necessary assets into runtime binary

Page 172: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

PerformanceSpriteKit Tips & Tricks NEW

Page 173: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

PerformanceSpriteKit Tips & Tricks

Performance tuning and battery life improvements

NEW

Page 174: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

PerformanceSpriteKit Tips & Tricks

Performance tuning and battery life improvements• SpriteKit now only renders when necessary

NEW

Page 175: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

PerformanceSpriteKit Tips & Tricks

Performance tuning and battery life improvements• SpriteKit now only renders when necessary• Additional ways to control the frame rate

NEW

Page 176: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

PerformanceSpriteKit Tips & Tricks

Performance tuning and battery life improvements• SpriteKit now only renders when necessary• Additional ways to control the frame rate

NEW

// Specify the desired FPS.

skView.preferredFramesPerSecond = 30

@objc public protocol SKViewDelegate : NSObjectProtocol {

// Dynamically control the render rate.

// - return YES to initiate an update and render for the target time.

// - return NO to skip update and render for this target time.

@objc public func view(_ view: SKView, shouldRenderAtTime time: TimeInterval) -> Bool

}

Page 177: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

PerformanceSpriteKit Tips & Tricks

Performance tuning and battery life improvements• SpriteKit now only renders when necessary• Additional ways to control the frame rate

NEW

// Specify the desired FPS.

skView.preferredFramesPerSecond = 30

@objc public protocol SKViewDelegate : NSObjectProtocol {

// Dynamically control the render rate.

// - return YES to initiate an update and render for the target time.

// - return NO to skip update and render for this target time.

@objc public func view(_ view: SKView, shouldRenderAtTime time: TimeInterval) -> Bool

}

Page 178: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

Page 179: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

What's New in SpriteKit

Page 180: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

What's New in SpriteKit• Scene Outline View

Page 181: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

What's New in SpriteKit• Scene Outline View• GameplayKit Integration

Page 182: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

What's New in SpriteKit• Scene Outline View• GameplayKit Integration• FPS Performance Gauge

Page 183: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

What's New in SpriteKit• Scene Outline View• GameplayKit Integration• FPS Performance Gauge• Tile Maps

Page 184: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

What's New in SpriteKit• Scene Outline View• GameplayKit Integration• FPS Performance Gauge• Tile Maps• Warp Transformation

Page 185: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

What's New in SpriteKit• Scene Outline View• GameplayKit Integration• FPS Performance Gauge• Tile Maps• Warp Transformation• Per-Node Attributes for Custom Shaders

Page 186: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

What's New in SpriteKit• Scene Outline View• GameplayKit Integration• FPS Performance Gauge• Tile Maps• Warp Transformation• Per-Node Attributes for Custom Shaders• Focus Interaction on Apple TV

Page 187: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Summary

What's New in SpriteKit• Scene Outline View• GameplayKit Integration• FPS Performance Gauge• Tile Maps• Warp Transformation• Per-Node Attributes for Custom Shaders• Focus Interaction on Apple TV• SpriteKit on Apple Watch

Page 188: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

More Information

https://developer.apple.com/wwdc16/610

Page 189: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Related Sessions

Go Live with ReplayKit Mission Tuesday 10:00AM

Focus Interaction on tvOS Mission Wednesday 4:00PM

Visual Debugging with Xcode Presidio Wednesday 4:00PM

Controlling Game Input for Apple TV Mission Wednesday 5:00PM

What’s New in GameplayKit Pacific Heights Thursday 9:00AM

Advances in SceneKit Rendering Mission Thursday 11:00AM

Page 190: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Related Sessions

What’s New in Game Center Mission Friday 10:00AM

Game Technologies for Apple Watch Mission Friday 3:00PM

Page 191: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,

Labs

Game Center Lab Graphics, Games, and Media Lab A Friday 12:00PM

SpriteKit Lab Graphics, Games, and Media Lab B Friday 12:00PM

watchOS Graphics and Games Lab Graphics, Games, and Media Lab B Friday 4:00PM

Page 192: What’s New in SpriteKit - Apple Developer · Framework features What Is SpriteKit? 2D graphics framework for games Flexible, easy to use, high-performance Supported on iOS, macOS,