LittleJS 1.28.0

LightSystem

DirectionalLight

A DirectionalLight is a sun for the 2D light system: it lights the whole scene from one direction, added into the lightmap with the point lights

  • One at a time, made after the LightSystemPlugin, lightSystem.directionalLight is the one; a debug build asserts on a second while the first lives, a release build destroys the first
  • Its castShadow lets foreground casters, objects with castShadow, throw long shadows across open space, fading out by shadowLength; a light does not need lightSystem.shadows for that
  • Objects with castBackgroundShadow, a background layer, are dark to it inside and lit at the edges that face it, fading in by backgroundDepth

Extends EngineObject

Constructor

new DirectionalLight(sunDirection, color)lightSystem.js:1179

Create the scene's directional light

sunDirection Vector2 optional

Toward the sun, it shines the other way, as render3D.sunDirection

color Color optional

Color of the light; alpha modulates intensity

new DirectionalLight(vec2(-1, 1), hsl(.1, .3, 1)); // a warm sun up and to the left, shining down and to the right

Members

Methods

Inherited from EngineObject

Members

backgroundDepth : numberlightSystem.js:1200

World units the light gets into a background area from its edges facing it

shadowLength : numberlightSystem.js:1198

World units a long shadow reaches before it has faded out; a caster casts only from inside the shadow map, shadowMapScale views across, so past (shadowMapScale - 1) / 2 of a view beyond the screen it throws none in

Toward the sun, it shines the other way, as render3D.sunDirection

Methods

destroy(immediate)lightSystem.js:1222

Destroy the light, the scene goes without it from the next frame

immediate boolean optional

A directional light draws nothing of its own, it is added into the lightmap by the plugin

Check its settings, called automatically each frame