A node that lights surrounding nodes.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
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.
SKLight object and an
SKSprite object add lighting to the scene if all of the following things are true:
The light node and the sprite node are both in the scene.
The light node’s
The light node’s
categoryproperty 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.
Sprite Node Mask
The sprite is lit by the light with specular, diffuse, and ambient lighting.
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.
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.