ig.

EntityLight

new EntityLight()

Light with options for dynamic, following, shadow casting, and more.
- inspired by illuminated.js.

Author:
  • Collin Hover - collinhover.com
Source:
Example
// creating lights is easy
// lets make one at the center of the world
var light = ig.game.spawnEntity( ig.EntityLight, 0, 0 );
// lights in Impact++ are not quite like 3D lights
// the difference being, you can actually see the light
// except our light is too small, so lets fix it
light.radius = 60;
// a light's appearance is controlled by r, g, b, and alpha
// so lets make it red
light.g = 0;
light.b = 0;
// for performance, lights are cached and static
// however, you can change its alpha dynamically
// but not its color, unless...
light.dynamicColor = true;
// one of the coolest features is shadow casting
light.castsShadows = true;
// but by default, all entities don't cast shadows
// unless we make them opaque
var dummy = ig.game.spawnEntity( ig.EntityDummy, 20, 0, {
     // it is important to note
     // that you should define opaque
     // when you create the entity
     // and not after
     // as Impact++ keeps a list
     // of all opaque entities
     // (to improve performance)
     // and this list only changes
     // when an entity is added or removed
     opaque: true
});
// now the above will work provided our light and dummy
// are added to the game at the same time
// because static lights only calculate shadows once
// but we can change this
light.performance = ig.EntityExtended.PERFORMANCE.MOVABLE;
// however, if our dummy is not static
dummy.performance = ig.EntityExtended.PERFORMANCE.DYNAMIC;
// our light will ignore it, unless...
light.castsShadowsMovable = true;
// also, to get shadows based on your level
// i.e. have your light cast shadows on the collision map
// you'll need to check out the game's "shapesPasses" property

_wmScalableLinked

Custom Weltmeister (editor) property.

Source:
Example
// to enable scalable entities to scale in both directions at once
// you'll need to edit the 'scaleSelectedEntity' method in weltmeister's 'edit-entities.js'
// add these two lines before the scaling
var _sizeLastX = this.selectedEntity.size.x;
var _sizeLastY = this.selectedEntity.size.y;
// and then add the following lines after the scaling
if ( this.selectedEntity._wmScalableLinked ) {

     if ( this.selectedEntity.size.x !== _sizeLastX ) {

         this.selectedEntity.size.y = this.selectedEntity.size.x;

     }
     else if ( this.selectedEntity.size.y !== _sizeLastY ) {

         this.selectedEntity.size.x = this.selectedEntity.size.y;

     }

}

alpha :Number

Alpha value from 0 to 1.

Source:

b :Number

Blue value from 0 to 1.

Source:

castsShadows :Boolean

Whether light should cast shadows on objects that are ig.EntityExtended#opaque.
- IMPORTANT: casting shadows can have a higher performance cost, use carefully!
- to cast shadows on movable entities, light ig.EntityExtended#performance must be movable and ig.EntityLight#castsShadowsMovable

Source:

castsShadowsMovable :Boolean

Whether light should cast shadows on movable objects that are ig.EntityExtended#opaque.
- IMPORTANT: casting shadows can have a higher performance cost, use carefully!
- to cast shadows, light must also ig.EntityLight#castsShadows
- doesn't work in combination with ig.EntityLight#pixelPerfect due to performance reasons

Source:

diffuse :Number

How much light should get through objects that are ig.EntityExtended#opaque.

Source:

dynamicColor :Boolean

Whether color can change dynamically in addition to alpha.
- be aware that this comes at a slightly higher performance cost

Default Value:
  • false
Source:

g :Number

Green value from 0 to 1.

Source:

gradient :Boolean

Whether light should be gradient or flat shaded.
- this works well in combination with ig.EntityLight#pixelPerfect

Source:

image :ig.ImageDrawing

Off screen canvas to cache complete light to improve performance.
- created on init

Source:

imageBase :ig.ImageDrawing

Off screen canvas to cache base light to improve performance.
- created on init

Source:

imageCast :ig.ImageDrawing

Off screen canvas to cache shadows to improve performance.
- created on init

Source:

imageColor :ig.ImageDrawing

Off screen canvas to cache light color to improve performance.
- created on init

Source:

<readonly> items :Array

List of items to cast shadows with.
- populated on update

Source:

layerName

Default Value:
  • lights
Source:

pixelPerfect :Boolean

Whether light should be drawn and scaled pixel perfectly. IMPORTANT: pixel perfect scaling has a very high performance cost, use carefully!
- doesn't work in combination with ig.EntityLight#castsShadowsMovable due to performance reasons

Source:

r :Number

Red value from 0 to 1.

Source:

radius

Size of light can be set either through ig.EntityLight#size or ig.EntityLight#radius property.
- if size is used, larger of x and y will become size and radius
- if radius is used, size will copy radius

Default Value:
  • 10
Source:

samples :Number

Number of passes to make when casting shadows.
- IMPORTANT: casting shadows can have a higher performance cost, use carefully!

Source:

size

Size of light can be set either through ig.EntityLight#size or ig.EntityLight#radius property.
- if size is used, larger of x and y will become size and radius
- if radius is used, size will copy radius

Default Value:
  • 10x10
Source:

castShadows()

Cast shadows of all ig.EntityLight#items for number of ig.EntityLight#samples using a spiral algorithm.

Source:

cleanup()

Source:

compute()

Computes the light and casted shadows.

Source:

draw()

Source:

drawLight()

Draws base light.

Source:

drawShadows()

Draw the shadows that are cast by items.

Source:

findItems()

Find all opaque items bounds that are ig.EntityExtended#opaque.

Source:

getRadius()

Calculates radius based on max size, used to find light bounds.

Source:
Returns:
radius.

getSizeDrawX()

Source:

getSizeDrawY()

Source:

initProperties()

Initializes light caches.

Source:

initTypes()

Initializes light types.
- adds ig.EntityExtended.TYPE.LIGHT to {@link ig.EntityExtended#type}

Source:

ready()

Sets light as ready and adds listener for system resize.

Source:

rebuild()

Source:

recordChanges()

Checks for base entity changes as well as alpha, color, and size changes.

Source:

resetCore()

Resets light core and ensures that radius and size match.

Source:

resize()

Source:

resizeCache()

Resize cache images for drawing.

Source:

updateBounds()

Lights update radius and draw pos is a copy of pos, but do not calculate bounds or vertices.

Source:

updateVisible()

Source: