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 properties that we can use to define its behavior:
lightingBitMask
: Thanks to this property, the sprite will be affected by the light with specular, diffuse, and ambient light.shadowCastBitMask
: Thanks to this property, a shadow will be created in...