iOS Developer Library

Developer

SpriteKit Framework Reference SKView Class Reference

Options
Deployment Target:

On This Page
Language:

SKView

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 YEStrue.

Import Statement


Swift

import SpriteKit

Objective-C

@import SpriteKit;

Availability


Available in iOS 7.0 and later.
  • Presents a scene.

    Declaration

    Swift

    func presentScene(_ scene: SKScene?)

    Objective-C

    - (void)presentScene:(SKScene *)scene

    Parameters

    scene

    The scene to present.

    Discussion

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

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Transitions from the current scene to a new scene.

    Declaration

    Swift

    func presentScene(_ scene: SKScene?, transition transition: SKTransition?)

    Objective-C

    - (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, the transition is executed to swap between the scenes. Otherwise, the new scene is presented immediately and the transition property is ignored.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • scene scene Property

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

    Declaration

    Swift

    var scene: SKScene? { get }

    Objective-C

    @property(nonatomic, readonly) SKScene *scene

    Discussion

    The default value is nil.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    var asynchronous: Bool

    Objective-C

    @property(nonatomic, getter=isAsynchronous) BOOL asynchronous

    Discussion

    The default value is YEStrue. If the value is NOfalse, the contents of this view are synchronized with Core Animation updates.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    var frameInterval: Int

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A Boolean property that indicates whether the view is rendered using transparency.

    Declaration

    Swift

    var allowsTransparency: Bool

    Objective-C

    @property(nonatomic) BOOL allowsTransparency

    Discussion

    This property tells the drawing system as to how it should treat the view. If set to NOfalse, the drawing system treats the view as fully opaque, which allows the drawing system to optimize some drawing operations and improve performance. If set to YEStrue, the drawing system composites the view normally with other content. The default value of this property is NOfalse.

    An opaque view is expected to fill its bounds with entirely opaque content—that is, the content should have an alpha value of 1.0. If the view is opaque and either does not fill its bounds or contains wholly or partially transparent content, the results are unpredictable. Always set the value of this property to NOfalse if the view is fully or partially transparent.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    var ignoresSiblingOrder: Bool

    Objective-C

    @property(nonatomic) BOOL ignoresSiblingOrder

    Discussion

    The default value is NOfalse, 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 YEStrue, 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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    zPosition

  • A Boolean value that indicates whether the view automatically culls non-visible nodes from the rendering tree.

    Declaration

    Swift

    var shouldCullNonVisibleNodes: Bool

    Objective-C

    @property(nonatomic) BOOL shouldCullNonVisibleNodes

    Discussion

    The default value is YEStrue, meaning that when the scene is rendered, the scene first searches the tree for invisible or offscreen nodes and culls them from the list of nodes to be rendered. Then the remaining (visible) nodes are processed and rendered. This is normally the desired behavior, because Scene Kit avoids expensive processing on nodes that cannot affect the final output. However, if your game is already managing the contents of the scene’s node tree (for example, by removing nodes from the tree when they are offscreen), you can set this to NOfalse to disable automatic scene culling. Disabling scene culling removes the performance overhead of this check, but each invisible or offscreen node present in the node tree reduces the performance of the renderer.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • paused paused Property

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

    Declaration

    Swift

    var paused: Bool

    Objective-C

    @property(nonatomic, getter=isPaused) BOOL paused

    Discussion

    If the value is YEStrue, the scene’s content is fixed onscreen. No actions are executed and no physics simulation is performed.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • showsFPS showsFPS Property

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

    Declaration

    Swift

    var showsFPS: Bool

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A Boolean value that indicates whether the view displays the number of rectangles used to render the scene.

    Declaration

    Swift

    var showsQuadCount: Bool

    Objective-C

    @property(nonatomic) BOOL showsQuadCount

    Discussion

    Sprite Kit converts the node tree into one or more rendering passes. Each rendering pass is rendered using a series of textured rectangles (quads). The showsQuadCount property allows you to see the total number of quads that were used to render the scene’s contents. Use this as another piece of data when you profile your game’s performance. In most cases, fewer quads is better.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

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

    Declaration

    Swift

    var showsDrawCount: Bool

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A Boolean value that indicates whether the view displays an overlay that shows physics bodies that are visible in the scene.

    Declaration

    Swift

    var showsNodeCount: Bool

    Objective-C

    @property(nonatomic) BOOL showsNodeCount

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    var showsPhysics: Bool

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • A Boolean value that indicates whether the view displays information about physics fields in the scene.

    Declaration

    Swift

    var showsFields: Bool

    Objective-C

    @property(nonatomic) BOOL showsFields

    Discussion

    When this debugging option is enabled, each time a frame is rendered, an image is drawn behind your scene that shows the effects of any physics fields contained in the scene.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • Converts a point from scene coordinates to view coordinates.

    Declaration

    Swift

    func convertPoint(_ point: CGPoint, fromScene scene: SKScene) -> CGPoint

    Objective-C

    - (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 is presented inside the view.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Converts a point from view coordinates to scene coordinates.

    Declaration

    Swift

    func convertPoint(_ point: CGPoint, toScene scene: SKScene) -> CGPoint

    Objective-C

    - (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 is presented inside the view.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Renders a portion of a node’s contents and returns the rendered image as a Sprite Kit texture.

    Declaration

    Swift

    func textureFromNode(_ node: SKNode, crop crop: CGRect) -> SKTexture!

    Objective-C

    - (SKTexture *)textureFromNode:(SKNode *)node crop:(CGRect)crop

    Parameters

    node

    The node object that is the root node of the tree you want to render to the texture.

    crop

    A rectangle in the node’s coordinate system that describes the area to be rendered.

    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 size of the crop rectangle. If the node is not a scene node, it is rendered with a clear background color ([SKColor clearColor]).

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • Renders the contents of a node tree and returns the rendered image as a Sprite Kit texture.

    Declaration

    Swift

    func textureFromNode(_ node: SKNode) -> SKTexture!

    Objective-C

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

    Parameters

    node

    The node object that is the root node of the tree 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]).

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.