Class

SKAttributeValue

A container for dynamic shader data associated with a node.

Declaration

@interface SKAttributeValue : NSObject

Overview

SpriteKit nodes that are rendered with a custom shader can use SKAttributeValue objects to pass dynamic values which can change without requiring that shader to be recompiled. An attribute value is passed to a shader using a node’s setValue:forAttributeNamed: method using the relevant attribute’s name. For example, given a shader with a SKAttributeTypeFloat attribute named a_radius:

Listing 1

Creating an attribute

let attribute = SKAttribute(name: "a_radius", 
                            type: SKAttributeType.float)

The following code sets the value of this attribute to 10 and passes it to a SKSpriteNode object’s shader:

Listing 2

Setting an attribute value

node.setValue(SKAttributeValue(float: 10), 
              forAttribute: "a_radius")

The attribute, a_radius, is available as a global floating-point variable within the shader code.

Using this technique, a single shader can be shared across many nodes and each nodes can supply its own attributes. This approach is an alternative to using SKUniform objects which would require a recompilation for each distinct set of parameters.

Topics

Initializers

- init

Creates and initializes a new attribute value object

+ valueWithFloat:

Creates and initializes a new attribute value object that holds a floating point number.

+ valueWithVectorFloat2:

Creates and initializes a new attribute value object that holds a vector of two floating point numbers.

+ valueWithVectorFloat3:

Creates and initializes a new attribute value object that holds a vector of three floating point numbers.

+ valueWithVectorFloat4:

Creates and initializes a new attribute value object that holds a vector of four floating point numbers.

Instance Properties

floatValue

The receiver’s floating point value.

vectorFloat2Value

The receiver’s value as a vector of two floating-point numbers.

vectorFloat3Value

The receiver’s value as a vector of three floating point numbers.

vectorFloat4Value

The receiver’s value as a vector of four floating point numbers.

Relationships

Inherits From

Conforms To

See Also

Shaders

SKShader

An object that allows you to apply a custom fragment shader.

SKAttribute

A specification for dynamic per-node data used with a custom shader.

SKUniform

A container for uniform shader data.