Class

SKLightNode

A node that lights surrounding nodes.

Declaration

@interface SKLightNode : SKNode

Overview

To use lighting, add a light node to the scene. Because lights are nodes, they can be moved or perform actions just like other nodes. However, light nodes are invisible except through their effects on sprite nodes configured to interact with them. When a sprite node is affected by a light, the lighting properties of the light node and the lighting properties of the sprite node determine what is rendered. Lighting may affect how unrelated portions of the scene are rendered. For example, if a sprite is configured to cast a shadow, the shadow is rendered on top of other content.

An SKLightNode object and an SKSpriteNode object add lighting to the scene if all of the following things are true:

  1. The light node and the sprite node are both in the scene.

  2. The light node’s enabled property is YES.

  3. The light node’s categoryBitMask property and one of the sprite’s lighting masks are logically combined using an AND operation, and the result is a nonzero number.

Table 1 describes the different kinds of effects that can be generated by a light, based on which mask is being tested on the sprite.

Table 1

Lighting effects

Sprite Node Mask

Effect

lightingBitMask

The sprite is lit by the light with specular, diffuse, and ambient lighting.

shadowCastBitMask

When the light casts a ray that intersects the light, a shadow is projected past the sprite, rendered on top of any content that is below the sprite.

shadowedBitMask

If the sprite is inside a shadow cast by a light and the sprite has a lower z position than the light, the shadow affects how the sprite is lit.

If any of the criteria are not met, the sprite is considered unlit and is rendered using the default behavior.

Topics

First Steps

Lighting a Sprite with Light Nodes

Add lighting and shadows to your scene with light nodes.

Determining Whether a Light Node Is Active

enabled

A Boolean value that indicates whether the node is casting light.

categoryBitMask

A mask that defines which categories this light belongs to.

Configuring the Lighting Properties

ambientColor

The ambient color of the light.

lightColor

The diffuse and specular color of the light source.

shadowColor

The color of any shadow cast by a sprite.

falloff

The exponent for the rate of decay of the light source.

Relationships

Inherits From

See Also

Nodes for Environmental Effects

SKAudioNode

A node that plays audio.

SKFieldNode

A node that applies physics effects to nearby nodes.