SKView Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/SpriteKit.framework
Availability
Available in iOS 7.0 and later.
Companion guide
Declared in
SKView.h

Overview

An SKView object is a view that displays Sprite Kit content. This content is provided by an SKScene object.

You present a scene by calling the view’s presentScene: method. When a scene is presented by the view, it alternates between running its simulation (which animates the content) and rendering the content for display. You can pause the scene by setting the view’s paused property to YES.

Tasks

Presenting Scenes

Pausing a Scene

Obtaining Images from Scene Content

Synchronizing Sprite Rendering with Core Animation

Displaying Debugging Information

Converting Between View and Scene Coordinates

Determining the Frame Rate

Configuring the Rendering Order of Scene

Properties

asynchronous

A Boolean value that indicates whether the content is rendered asynchronously.

@property(getter=isAsynchronous, nonatomic) BOOL asynchronous
Discussion

The default value is YES. If the value is NO, then the contents of this view are synchronized with Core Animation updates.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

frameInterval

The number of frames that must pass before the scene is called to update its contents.

@property(nonatomic) NSInteger frameInterval
Discussion

The default value is 1, which results in your game being notified at the refresh rate of the display. If the value is set to a value larger than 1, the display link notifies your game at a fraction of the native refresh rate. For example, setting the interval to 2 causes the scene to be called every other frame, providing half the frame rate.

Setting this value to less than 1 results in undefined behavior and is a programmer error.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

ignoresSiblingOrder

A Boolean value that indicates whether parent-child and sibling relationships affect the rendering order of nodes in the scene.

@property(nonatomic) BOOL ignoresSiblingOrder
Discussion

The default value is NO, which means that when multiple nodes share the same z position, those nodes are sorted and rendered in a deterministic order. Parents are rendered before their children, and siblings are rendered from eldest to youngest. When this property is set to YES, the position of the nodes in the tree is ignored when determining the rendering order. The rendering order of nodes at the same z position is arbitrary and may change every time a new frame is rendered. When sibling and parent order is ignored, Sprite Kit applies additional optimizations to improve rendering performance. If you need nodes to be rendered in a specific and deterministic order, you must set the z position of those nodes.

Availability
  • Available in iOS 7.0 and later.
See Also
Declared In
SKView.h

paused

A Boolean value that indicates whether the view’s scene animations are paused.

@property(getter=isPaused, nonatomic) BOOL paused
Discussion

If the value is YES, then the scene’s content is fixed on screen. No actions are executed and no physics simulation is performed.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

scene

The scene currently presented by the view. (read-only)

@property(readonly, nonatomic) SKScene *scene
Discussion

The default value is nil.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

showsDrawCount

A Boolean value that indicates whether the view displays the number of drawing passes it needed to render the view.

@property(nonatomic) BOOL showsDrawCount
Discussion

Some operations in Sprite Kit can require multiple rendering passes to draw a scene’s content. For example, an SKEffectNode object must render its children into a separate buffer, apply the effect, and then perform another pass to blend those results into its parent node. These additional rendering passes use more rendering resources, reducing your game’s frame rate or increasing its total power consumption. Use the draw count as another piece of data when you profile your game’s performance.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

showsFPS

A Boolean value that indicates whether the view displays a frame rate indicator.

@property(nonatomic) BOOL showsFPS
Discussion

The frame rate is a good indicator of the performance of your scene. Avoid creating scenes that have widely varying frame rates.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

showsNodeCount

A Boolean value that indicates whether the view displays the count of the nodes visible in the scene.

@property(nonatomic) BOOL showsNodeCount
Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

showsPhysics

A Boolean value that indicates whether the view displays physics-related debugging information.

@property(nonatomic) BOOL showsPhysics
Discussion

When this debugging option is enabled, each time a frame is rendered, an overlay image is drawn on top of your scene that shows the positions and shapes of any physics bodies visible in the scene.

Availability
  • Available in iOS 7.1 and later.
Declared In
SKView.h

Instance Methods

convertPoint:fromScene:

Converts a point from scene coordinates to view coordinates.

- (CGPoint)convertPoint:(CGPoint)point fromScene:(SKScene *)scene
Parameters
point

A point in scene coordinates.

scene

A scene.

Return Value

The same point in the view’s coordinate system.

Discussion

This method performs the coordinate conversion as if the scene were presented inside the view.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

convertPoint:toScene:

Converts a point from view coordinates to scene coordinates.

- (CGPoint)convertPoint:(CGPoint)point toScene:(SKScene *)scene
Parameters
point

A point in view coordinates.

scene

A scene.

Return Value

The same point in the scene’s coordinate system.

Discussion

This method performs the coordinate conversion as if the scene were presented inside the view.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

presentScene:

Presents a scene.

- (void)presentScene:(SKScene *)scene
Parameters
scene

The scene to present.

Discussion

The new scene immediately replaces the current scene, if one exists.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

presentScene:transition:

Transitions from the current scene to a new scene.

- (void)presentScene:(SKScene *)scene transition:(SKTransition *)transition
Parameters
scene

The scene to present.

transition

A transition used to animate between the two scenes.

Discussion

If there is currently a scene presented by the view, the view’s scene property is updated immediately, then the transition is executed to swap between the scenes. Otherwise, the new scene is presented immediately and the transition property is ignored.

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h

textureFromNode:

Renders and returns a Sprite Kit texture that contains the node’s contents.

- (SKTexture *)textureFromNode:(SKNode *)node
Parameters
node

A node object representing the content you want to render to the texture.

Return Value

A Sprite Kit texture that holds the rendered image.

Discussion

The node being rendered does not need to appear in the view’s presented scene. The new texture is created with a size equal to the rectangle returned by the node’s calculateAccumulatedFrame method. If the node is not a scene node, it is rendered with a clear background color ([SKColor clearColor]).

Availability
  • Available in iOS 7.0 and later.
Declared In
SKView.h