A lighting/shadow engine for the ImpactJS game engine
- Standalone. Doesn't depend on Impact++ or other large libraries.
- Simple. Lights are just ImpactJS
Entity
s, and can be created and manipulated the same way you would do for any otherEntity
. Shadow-casting lights integrate seamlessly withCollisionMap
so that collision tiles of any shape cast shadows. - Configurable. Change the color, smoothness, and gradient of your lights. Whether or not lights cast shadows can also be configured.
- Extensible. Though the library currenly only implements point lights, it's simple to implement other types of lights.
- Dynamic. Moving lights, moving objects, and moving shadows.
- Copy the shade source (the folder containing "main.js") into a folder called "shade" in your ImpactJS project's "lib/plugins" folder.
- Register the plugin in your own "main.js" file:
.requires(
'plugins.shade.main'
)
- Create
sh.Light
entities in your game. You can do this programmatically byrequire
ing'plugins.shade.light'
and callingig.game.spawnEntity(sh.Light, x, y, settings)
. Alternatively, you can add it to a map using Weltmeister. The easiest way to exposesh.Light
to Weltmeister is to create a simple subclass in your "lib/game/entities" folder:
ig.module(
'game.entities.light'
).requires(
'plugins.shade.light'
).defines(function () {
EntityLight = sh.Light.extend({ });
});
shade sh.Light
s are created just like any other Entity
in ImpactJS. To configure an sh.Light
, simply pass in settings via Game.spawnEntity
or via Weltmeister. sh.Light
supports the following options:
size
The size of the light.gradient
Set totrue
to indicate that this light should have a gradient.color
A color object of the form{ r, g, b }
. Changing this at any time after theLight
has already been initialized will immediately update theLight
.smooth
Set this tofalse
to get a "retro"/pixelated look proportional toig.game.scale
.shadows
Set this tofalse
to prevent this light from creating shadows when objects are in its way. Not casting shadows is better for performance.
In addition to Light
, there is also a global sh.LightManager
. The only really interesting thing about the light manager is that you can change the global ambient light by modifying the color
property on the global sh.lightManager
.
One new property has been added to ig.Entity
's prototype as well: the opaque
property. When set to false
, the given Entity
will not cast shadows. When set to true
a shadow will be cast by the given Entity
's bounding rectangle (as determined by its position and size). This property can also be set to an Array
of { x, y }
points defining a concave polygon to be used for shadow casting instead of its bounding rectangle.