Turning on the lights

One of the most important elements in a game is lighting as it helps you give the desired atmosphere or highlight some places on the scene.

SpriteKit provides the SKLightNode class that gives us the capability of creating lights and treating them as nodes and, as a consequence of that, we can decide which nodes on the scene will interact with the lights, casting shadows.

It's important to take into account that even though lights are nodes, they have no visual representation unless we associate a sprite node to it. We also need to bear in mind that it's possible that the shadows produced by a source of light will be shown over other nodes.

When allowing a node to be affected by a source of light in the scene, there are three ...

Get Getting Started with SpriteKit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.