Class

SKSpriteNode

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

Overview

An SKSpriteNode is a node that draws a texture (optionally blended with a color), an image, a colored square. You can also provide a custom shader to create your own rendering effects.

Sprite nodes can be lit with SKLightNode objects and optionally cast and receive shadows. 3D lighting can be simulated by supplying a separate normal texture or automatically generating a normal texture from an image.

Symbols

Initializing a New Sprite

init(color: UIColor, size: CGSize)

Initializes a colored sprite.

init(imageNamed: String)

Initializes a textured sprite using an image file.

init(texture: SKTexture?)

Initializes a textured sprite using an existing texture object.

init(texture: SKTexture?, color: UIColor, size: CGSize)

Initializes a colored and textured sprite using an existing texture object.

init(texture: SKTexture?, size: CGSize)

Initializes a textured sprite using an existing texture object but with a specified size.

init(imageNamed: String, normalMapped: Bool)

Initializes a textured sprite using an image file, optionally adding a normal map to simulate 3D lighting.

init(texture: SKTexture?, normalMap: SKTexture?)

Initializes a textured sprite with a normal map to simulate 3D lighting.

Inspecting Physical Properties

var size: CGSize

The dimensions of the sprite, in points.

func scale(to: CGSize)

Scales to sprite node to a specified size.

var anchorPoint: CGPoint

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

Inspecting the Sprite’s Texture

var texture: SKTexture?

The texture used to draw the sprite.

var centerRect: CGRect

A property that defines how the texture is applied to the sprite.

var colorBlendFactor: CGFloat

A floating-point value that describes how the color is blended with the sprite’s texture.

Inspecting Color Properties

var color: UIColor

The sprite’s color.

Blending the Sprite with the Framebuffer

var blendMode: SKBlendMode

The blend mode used to draw the sprite into the parent’s framebuffer.

Adding Lighting to a Sprite

var lightingBitMask: UInt32

A mask that defines how this sprite is lit by light nodes in the scenes.

var shadowedBitMask: UInt32

A mask that defines which lights add additional shadows to the sprite.

var shadowCastBitMask: UInt32

A mask that defines which lights are occluded by this sprite.

var normalTexture: SKTexture?

A texture that specifies the normal map for the sprite.

Working with Custom Shaders

var shader: SKShader?

A property that determines whether the sprite is rendered using a custom shader.

var attributeValues: [String : SKAttributeValue]

The values of each attribute associated with the node's attached shader.

Beta
func setValue(SKAttributeValue, forAttribute: String)

Sets an attribute value for an attached shader.

Beta
func value(forAttributeNamed: String)

The value of a shader attribute.

Beta

Instance Properties

var customPlaygroundQuickLook: PlaygroundQuickLook

A custom playground quick look for this instance.

Instance Methods

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software