iOS Developer Library — Prerelease

Developer

SpriteKit Framework Reference SK3DNode Class Reference

Options
Deployment Target:

On This Page
Language:

SK3DNode

A SK3DNode object is a Sprite Kit node that renders a Scene Kit scene as a 2D textured image. Use SK3DNode objects to incorporate Scene Kit content into a Sprite Kit-based game. When Sprite Kit renders the node, the Scene Kit scene is animated and rendered first. Then this rendered image is composited into the Sprite Kit scene.

Use the scnScene property to specify the Scene Kit scene to be rendered.

  • Creates and initializes a new 3D node.

    Declaration

    Objective-C

    + (instancetype _Nonnull)nodeWithViewportSize:(CGSize)viewportSize

    Parameters

    viewportSize

    The size of the node’s rendered image.

    Return Value

    A newly created and initialized SK3DNode object.

    Discussion

    The node must be configured with a Scene Kit scene before it renders anything.

    Availability

    Available in iOS 8.0 and later.

  • Initializes a new 3D node.

    Declaration

    Swift

    init(viewportSize viewportSize: CGSize)

    Objective-C

    - (instancetype _Nonnull)initWithViewportSize:(CGSize)viewportSize

    Parameters

    viewportSize

    The size of the node’s rendered image.

    Return Value

    An initialized SK3DNode object.

    Availability

    Available in iOS 8.0 and later.

  • The size of the image rendered by the node.

    Declaration

    Swift

    var viewportSize: CGSize

    Objective-C

    @property CGSize viewportSize

    Availability

    Available in iOS 8.0 and later.

  • The Scene Kit scene to render.

    Declaration

    Swift

    var scnScene: SCNScene?

    Objective-C

    @property(nonatomic, retain, nullable) SCNScene *scnScene

    Availability

    Available in iOS 8.0 and later.

  • The Scene Kit node from which the scene’s contents are viewed when rendered.

    Declaration

    Swift

    var pointOfView: SCNNode?

    Objective-C

    @property(nonatomic, retain, nullable) SCNNode *pointOfView

    Discussion

    Use a SCNNode object with an SCNCamera instance assigned to its camera property to view a scene. This Scene Kit node provides the position and direction of a virtual camera, and the camera object provides rendering parameters such as field of view and focus. The direction of view is along the negative z-axis of the Scene Kit node’s local coordinate space.

    Availability

    Available in iOS 8.0 and later.

  • A Boolean value that determines whether Scene Kit automatically adds lights to a scene.

    Declaration

    Swift

    var autoenablesDefaultLighting: Bool

    Objective-C

    @property(nonatomic) BOOL autoenablesDefaultLighting

    Discussion

    If this property’s value is NOfalse (the default), the only light sources Scene Kit uses for rendering a scene are those contained in the scene graph. If you change the value to YEStrue, Scene Kit automatically adds and places an omnidirectional light source when rendering scenes that contain no lights or only contain ambient lights.

    Availability

    Available in iOS 8.0 and later.

  • A Boolean value that determines whether the scene is playing.

    Declaration

    Swift

    var playing: Bool

    Objective-C

    @property(getter=isPlaying) BOOL playing

    Discussion

    If the value of this property is NOfalse (the default), Scene Kit does not increment the scene time, so animations associated with the scene do not play. Change this property’s value to YEStrue to start animating the scene.

    Availability

    Available in iOS 8.0 and later.

  • A Boolean value that determines whether Scene Kit restarts the scene time after all animations in the scene have played.

    Declaration

    Swift

    var loops: Bool

    Objective-C

    @property(nonatomic) BOOL loops

    Discussion

    If the value of this property is YEStrue (the default), Scene Kit returns the scene time to zero after all animations associated with the scene have played, causing those animations to repeat. Otherwise, Scene Kit stops playing the scene when all animations have completed.

    Availability

    Available in iOS 8.0 and later.

  • The current scene time.

    Declaration

    Swift

    var sceneTime: NSTimeInterval

    Objective-C

    @property(nonatomic) NSTimeInterval sceneTime

    Discussion

    This timestamp determines the behavior of running animations, similar to how the playhead time in a video player application determines which frame of a movie to display. It applies only to animations whose usesSceneTimeBase property is YEStrue, including those loaded from a scene source using the SCNSceneSourceAnimationImportPolicyPlayUsingSceneTimeBase option.

    Use this property together with the above animation options when you want to directly control (or allow the user to directly control) the playback of animations.

    Availability

    Available in iOS 8.0 and later.

  • Searches the Scene Kit scene for objects corresponding to a point in the rendered image.

    Declaration

    Swift

    func hitTest(_ point: CGPoint, options options: [String : AnyObject]?) -> [SCNHitTestResult]

    Objective-C

    - (NSArray<SCNHitTestResult *> * _Nonnull)hitTest:(CGPoint)thePoint options:(NSDictionary<NSString *,id> * _Nullable)options

    Parameters

    thePoint

    A point in the viewport coordinate system of the Sprite Kit node.

    options

    A dictionary of options affecting the search. See Hit Testing Options Keys for acceptable values.

    Return Value

    An array of SCNHitTestResult objects representing search results.

    Discussion

    A point in the Sprite Kit node’s 2D viewport coordinate space can refer to any point along a line segment in the 3D Scene Kit coordinate space. Hit-testing is the process of finding elements of a scene located along this line segment. For example, you can use this method to find the geometry corresponding to a touch event.

    Availability

    Available in iOS 8.0 and later.

  • Projects a point from the 3D world coordinate system of the Scene Kit scene to the 2D viewport coordinate system of the Sprite Kit node.

    Declaration

    Swift

    func projectPoint(_ point: vector_float3) -> vector_float3

    Objective-C

    - (vector_float3)projectPoint:(vector_float3)point

    Parameters

    point

    A point in the world coordinate system of the Scene Kit scene.

    Return Value

    The corresponding point in the Sprite Kit node’s coordinate system.

    Discussion

    The z-coordinate of the returned point describes the depth of the projected point relative to the near and far clipping planes of the viewing frustum (defined by the pointOfView property). Projecting a point on the near clipping plane returns a point whose z-coordinate is 0.0; projecting a point on the far clipping plane returns a point whose z-coordinate is 1.0.

    Availability

    Available in iOS 8.0 and later.

  • Unprojects a point from the Sprite Kit node’s 2D viewport coordinate system to the 3D world coordinate system of the Scene Kit scene.

    Declaration

    Swift

    func unprojectPoint(_ point: vector_float3) -> vector_float3

    Objective-C

    - (vector_float3)unprojectPoint:(vector_float3)point

    Parameters

    point

    A point in the Sprite Kit node’s coordinate system.

    Return Value

    The corresponding point in the world coordinate system of the Scene Kit scene.

    Discussion

    The z-coordinate of the point parameter describes the depth at which to unproject the point relative to the near and far clipping planes of the viewing frustum (defined by the pointOfView property). Unprojecting a point whose z-coordinate is 0.0 returns a point on the near clipping plane; unprojecting a point whose z-coordinate is 1.0 returns a point on the far clipping plane.

    A point in the Sprite Kit node’s 2D viewport coordinate space can refer to any point along a line segment in the 3D Scene Kit coordinate space. To test for scene contents along this line—for example, to find the geometry corresponding to a touch event—use the hitTest:options: method.

    Availability

    Available in iOS 8.0 and later.