Class

SKVideoNode

A node that displays video content.

Overview

Like any other node, you can put the movie node anywhere inside the node tree and Sprite Kit 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.

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

SKVideoNode 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

SKVideoNode *sample = [SKVideoNode videoNodeWithFileNamed:@"sample.m4v"];
sample.position = CGPointMake(CGRectGetMidX(self.frame),
                                 CGRectGetMidY(self.frame));
[self addChild: sample];
[sample play];

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 AV Foundation 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.

Symbols

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.

Deprecated
init(videoURL: URL)

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

Deprecated

Relationships

Inherits From

Conforms To