Class l2df.class.component.states
States component.
Inherited from l2df.class.Component class.
Info:
- Copyright: Atom-TM 2019
- Author: Kasai
Functions
States:added(obj[, kwargs]) | Component was added to Entity event. |
States:removed(obj) | Component was removed from Entity event. |
States:add(obj, state, id[, use_constate=false]) | Add new state to the collection. |
States:remove(obj, id[, use_constate=false]) | Remove previously added state by ID. |
States:clear(obj[, use_constate=false]) | Clears all added states (or constant states). |
States:update(obj, dt) | Component update event handler. |
Tables
State | State description table. |
ConstantState | Constant state description table. |
Functions
Methods- States:added(obj[, kwargs])
-
Component was added to Entity event.
Adds
"states"
key to the Entity.C table.Parameters:
- obj l2df.class.entity Entity's instance.
-
kwargs
table
Keyword arguments.
- constates {l2df.class.component.states.ConstantState,...} Array of constant states which will be processed at each States:update() event. (optional)
- States:removed(obj)
-
Component was removed from Entity event.
Removes
"states"
key from Entity.C table.Parameters:
- obj l2df.class.entity Entity's instance.
- States:add(obj, state, id[, use_constate=false])
-
Add new state to the collection.
Parameters:
- obj l2df.class.entity Entity's instance.
- state l2df.class.component.states.State or l2df.class.component.states.ConstantState State description table.
-
id
number or string
ID of the state to be added. Used for calling StatesManager:run() function.
Also ID could be provided as
state[1]
(first array index in the state variable). This ID couldn't be used in States:remove(), use returned value instead. -
use_constate
boolean
Set to
true
to add state as constant state. (default false)
Returns:
-
number
ID of the state added in a local storage.
- States:remove(obj, id[, use_constate=false])
-
Remove previously added state by ID.
Parameters:
- obj l2df.class.entity Entity's instance.
- id number ID of the state to remove.
-
use_constate
boolean
Set to
true
if you are removing constant state. (default false)
- States:clear(obj[, use_constate=false])
-
Clears all added states (or constant states).
Parameters:
- obj l2df.class.entity Entity's instance.
-
use_constate
boolean
Set to
true
to clear all constant states. (default false)
- States:update(obj, dt)
-
Component update event handler.
Executes all added states and constant states.
All added states are removed after processing (except for constant states, they can be removed manually only).
Parameters:
- obj l2df.class.entity Entity's instance.
- dt number Delta-time since last game tick.
Tables
- State
-
State description table.
Fields:
- ... There're may be any amount of the <key:value> pairs. All of them can be accessed from the 3rd table argument passed to the state's function. For more info see StatesManager:run().
- ConstantState
-
Constant state description table.
Currently it is absolutely similar with State.
Fields:
- ... There're may be any amount of the <key:value> pairs. All of them can be accessed from the 3rd table argument passed to the state's function. For more info see StatesManager:run().