A node that displays video content.


Like any other node, you can put the movie node anywhere inside the node tree and SpriteKit will render it properly. For example, you might use a video node to animate some visual behaviors that would be expensive to define using a collection of textures.

A video node offers only a subset of the features available to the SKSpriteNode class:

  • A video node is always stretched uniformly.

  • A video node cannot be colorized. However, a video node can be added as a child of a SKEffectNode to add Core Image filters for color treatments and other effects.

  • A video node always uses an alpha blend mode.

  • A video node cannot use custom shaders or lighting.

When a video node is created, its size property is initialized to the base size of the video content, but you can change it if you want. The video content is automatically stretched to the new size. As with a sprite node, the anchorPoint property defines where the content is displayed relative to the node position.

Listing 1 initializes the video node using a video file stored in the app bundle and then adds the node to the scene. It calls the node’s play() method to start the video playback.

Listing 1

Displaying a video in a scene

let sample = SKVideoNode(fileNamed: "")
sample.position = CGPoint(x: frame.midX,
                          y: frame.midY)

You control playback using the node’s play() and pause() methods.

If you need more precise control over the video playback behavior, you can use AVFoundation to create an AVPlayer object for your video content and then use this object to initialize the SKVideoNode node. Then, instead of using the node’s playback methods, you use the AVPlayer object to control playback. The video content is automatically displayed in the video node. For more information, see AVFoundation Programming Guide.


Creating a Video Node

init(avPlayer: AVPlayer)

Initializes a video node using an existing AVPlayer object.

init(fileNamed: String)

Initializes a video node using a video file stored in the app bundle.

init(url: URL)

Initializes a video node using a URL.

Setting the Video Node’s Visual Properties

var anchorPoint: CGPoint

Defines the point in the sprite that corresponds to the node’s position.

var size: CGSize

The dimensions of the video node, in points.

Controlling Video Playback

func play()

Starts video playback.

func pause()

Pauses video playback.

Deprecated Methods

init(videoFileNamed: String)

Initializes a video node using a video file stored in the app bundle.

init(videoURL: URL)

Initializes a video node using a URL that points to a video file.


See Also

Nodes That Draw Content

class SKSpriteNode

A node that draws a rectangular texture, image or color.

class SKShapeNode

A node that renders a shape defined by a Core Graphics path.

class SKLabelNode

A node that displays a text label.

class SKCropNode

A node that masks pixels drawn by its children so that only some are rendered to the parent’s frame buffer.

class SKReferenceNode

A node that creates its children from an archived collection of other nodes.