LightingModel.new()

   
Type function
Library wattageTileEngine.LightingModel.*
Return value LightingModel
Keywords  
See also  

Overview

This function creates a new instance of LightingModel.

Syntax

LightingModel.new( params )
params (required)

Table. Contains all required inputs. See Required Properties below.

Required Properties

The params table contains the following properties:

isTransparent (required)

function. Callback which returns true if the tile is transparent. The callback must have the following signature:

boolean function(column, row)
isTileAffectedByAmbient (required)

function. Callback which returns true if the tile is affected by ambient lighting. The callback must have the following signature:

boolean function(row, column)
useTransitioners (required)

boolean. True if the changes in lighting should transition smoothly. Setting this to false will result in lighting conditions changing immediately. Setting to true will apply the changes gradually over 250 milliseconds.

compensateLightingForViewingPosition (required)

boolean. This must be set to true if the engine also has it set to true. However, doing so does require additional overhead which can affect performance.

Examples

local TileEngine = require "plugin.wattageTileEngine"

-- Callback to indicate whether light can pass through a tile
local function isTransparentForLight(column, row)
    -- Make an opaque wall along column 5
    return column ~= 5
end

-- Callback to indicate whether a tile is affected by ambient lighting.
local function isTileAffectedByAmbient(row, column)
    -- Make all tiles affected by ambient lighting
    return true
end

local lightingModel = TileEngine.LightingModel.new({
    isTransparent = isTransparentForLight,
    isTileAffectedByAmbient = isTileAffectedByAmbient,
    useTransitioners = true,
    compensateLightingForViewingPosition = false
})