A texture whose contents can be dynamically updated.


Normally, SpriteKit textures (SKTexture objects) are static, meaning that once created, their contents cannot be changed. This is important because a static image can be more efficiently managed inside the graphics hardware. However, sometimes you need to be able to update the contents of a texture dynamically. In this case, you should use a mutable texture. Because there is a performance penalty for updating the texture’s contents, consider other options first. For example, you can render a texture in hardware using the texture(from:) method and a node tree.

To use this class, create a mutable texture using either one of its creation methods or those of its superclass. Then, when you need to update the mutable texture object’s contents, call the modifyPixelData(_:) method. Your block is called with the location of the texture in memory. Your block should update this texture and then return.


Creating an Empty Mutable Texture

init(size: CGSize, pixelFormat: Int32)

Initializes an empty texture with a specific size and format.

init(size: CGSize)

Initializes an empty texture with a specific size.

Modifying a Mutable Texture’s Contents

func modifyPixelData((UnsafeMutableRawPointer?, Int) -> Void)

Modifies the contents of a mutable texture.

See Also

Working with Textures

class SKTexture

A representation of an image for use in SpriteKit.

class SKTextureAtlas

A collection of textures.