Class

SKScene

An object that organizes all of the active SpriteKit content.

Declaration

@interface SKScene : SKEffectNode

Overview

An SKScene object represents a scene of content in SpriteKit. A scene is the root node in a tree of SpriteKit nodes (SKNode). These nodes provide content that the scene animates and renders for display. To display a scene, you present it from an SKView, SKRenderer, or WKInterfaceSKScene.

SKScene is a subclass of SKEffectNode and enables certain effects to apply to the entire scene. Though applying effects to an entire scene can be an expensive operation, creativity, and ingenuity may help you find some interesting ways to use effects.

Topics

Creating a Scene from a File

Creating a Scene from a File

Load a scene that you configure in Xcode's scene editor.

Creating a Scene Programmatically

Use code to manually create a scene and configure its properties.

+ sceneWithSize:

Creates and returns a new scene object.

- initWithSize:

Initializes a new scene object.

size

The dimensions of the scene, in points.

Stretching Content to Fit the View

Scaling a Scene's Content to Fit the View

Configure the scale mode to determine how a scene is sized to fit its view.

scaleMode

A setting that defines how the scene is mapped to the view that presents it.

SKSceneScaleMode

The modes that determine how the scene’s area is mapped to the view that presents it.

Configuring the Viewport

Define which portion of the scene is visible at a given time.

Positioning a Scene's Origin Within its View

Try the different ways to configure the scene's origin inside its view.

camera

The camera node in the scene that determines what part of the scene’s coordinate space is visible in the view.

anchorPoint

The point in the view’s frame that corresponds to the scene’s origin.

Responding to Loading and Resizing Events

Override these functions to be notified when a scene is loaded or presented, or changes size.

- sceneDidLoad

Tells you when the scene is presented.

- didChangeSize:

Tells you when the scene’s size has changed.

- willMoveFromView:

Tells you when the scene is about to be removed from a view.

- didMoveToView:

Tells you when the scene is presented by a view.

Responding to Frame-Cycle Events

Callbacks occur every frame, telling you when to perform app logic.

Responding to Frame-Cycle Events

Implement per-frame app logic, such as the scene's update function that's called every frame.

- update:

Tells your app to perform any app-specific logic to update your scene.

- didEvaluateActions

Tells your app to peform any necessary logic after scene actions are evaluated.

- didSimulatePhysics

Tells your app to peform any necessary logic after physics simulations are performed.

- didApplyConstraints

Tells your app to peform any necessary logic after constraints are applied.

- didFinishUpdate

Tells your app to peform any necessary logic after the scene has finished all of the steps required to process animations.

Configuring a Delegate

Instead of subclassing a scene to respond to update life-cycle events, assign a delegate to field them.

Subclassing Scenes Versus Assigning a Delegate

Use a scene delegate to share app logic across various scenes.

delegate

A delegate to be called during the animation loop.

SKSceneDelegate

Methods that, when implemented, allow any class to participate in the SpriteKit render loop callbacks.

Setting the Background Appearance

Adjust content that's under a scene.

Creating a Scene with a Transparent Background

Set a transparent background color to show the content of the views below.

view

The view that is currently presenting the scene.

backgroundColor

The background color of the scene.

Configuring Physics Properties

physicsWorld

The physics simulation associated with the scene.

Adding Positional Audio

Enable positional audio by defining a listener.

Using Audio Nodes with the Scene's Listener

Add audio to your scene, and optionally give it 2D-positional mixing characteristics.

listener

A node used to determine the position of the listener for positional audio in the scene.

audioEngine

The AVFoundation audio engine used to play audio from audio nodes contained in the scene.

Converting Between Coordinate Systems

- convertPointFromView:

Converts a point from view coordinates to scene coordinates.

- convertPointToView:

Converts a point from scene coordinates to view coordinates.

Relationships

Inherits From

See Also

Essentials

Drawing SpriteKit Content in a View

Display visual content using SpriteKit.

Nodes for Scene Building

Define the appearance or layout of scene content.