ScriptComponent

ScriptComponent

Manages a collection of scripts assoicated with an entity.

Constructor

new ScriptComponent(scriptsopt)

Initializes a ScriptComponent object.

Parameters:
Name Type Attributes Description
scripts Script | Array.<Script> <optional>

A script-object or an array of
script-objects to attach to the entity.

Methods

(static) applyOnEntity(obj, entity) → {boolean}

Attempts to add a script object to an entity.

Parameters:
Name Type Description
obj Script

The possible script object. If the object has a setup
update, fixedUpdate or cleanup function is is considered to
be a script object.

entity Entity

The entity

addScript(script)

Add a script to this component. See ScriptSystem for more
information on how scripts are executed by the system.

Parameters:
Name Type Description
script Script

The script to add.

attachScriptSystem(scriptSystem)

Parameters:
Name Type Description
scriptSystem ScriptSystem

The ScriptSystem to which the component
was attached.

clearScripts()

Removes all of this component's scripts.

clone()

Clones all the scripts managed by this component. This function is called
by EntityUtils.clone.

detachScriptSystem()

ensureCanReplaceComponent(sourceEntity)

validate if the current component support entity replacing. By default, it does not support.

Parameters:
Name Type Description
sourceEntity Entity
Throws:

Error if the entity contains this component is not replaceable

getScripts() → {Set.<Script>}

Gets the scripts managed by this component.

removeScript(script)

Remove a script from this component.

Parameters:
Name Type Description
script Script

The script to remove.

setScripts(scripts)

Set this component's scripts. All existing scripts are removed. See
ScriptSystem for more information on how scripts are executed by
the system.

Parameters:
Name Type Description
scripts Array.<Script>

The scripts to add.