Skip to main content

Unit

Description:

  A class represents a character or other interactive item in a game scene.

Class Object: Platformer.Unit Class.

Inherits from: Body.

playable

Type: Field.

Description:

  A property that references a "Playable" object for managing the animation state and playback of the "Unit".

Signature:

playable: Playable

detectDistance

Type: Field.

Description:

  A property that specifies the maximum distance at which the "Unit" can detect other "Unit" or objects.

Signature:

detectDistance: number

attackRange

Type: Field.

Description:

  A property that specifies the size of the attack range for the "Unit".

Signature:

attackRange: Size

faceRight

Type: Field.

Description:

  A boolean property that specifies whether the "Unit" is facing right or not.

Signature:

faceRight: boolean

receivingDecisionTrace

Type: Field.

Description:

  A boolean property that specifies whether the "Unit" is receiving a trace of the decision tree for debugging purposes.

Signature:

receivingDecisionTrace: boolean

decisionTree

Type: Field.

Description:

  A string property that specifies the decision tree to use for the "Unit's" AI behavior. The decision tree object will be searched in The singleton instance Data.store.

Signature:

decisionTree: string

onSurface

Type: Readonly Field.

Description:

  Whether the "Unit" is currently on a surface or not.

Signature:

const onSurface: boolean

groundSensor

Type: Readonly Field.

Description:

  A "Sensor" object for detecting ground surfaces.

Signature:

const groundSensor: Sensor

detectSensor

Type: Readonly Field.

Description:

  A "Sensor" object for detecting other "Unit" objects or physics bodies in the game world.

Signature:

const detectSensor: Sensor

attackSensor

Type: Readonly Field.

Description:

  A "Sensor" object for detecting other "Unit" objects within the attack senser area.

Signature:

const attackSensor: Sensor

unitDef

Type: Readonly Field.

Description:

  A "Dictionary" object for defining the properties and behavior of the "Unit".

Signature:

const unitDef: Dictionary

currentAction

Type: Readonly Field.

Description:

  A property that specifies the current action being performed by the "Unit".

Signature:

const currentAction: UnitAction

width

Type: Readonly Field.

Description:

  The width of the "Unit".

Signature:

const width: number

height

Type: Readonly Field.

Description:

  The height of the "Unit".

Signature:

const height: number

entity

Type: Readonly Field.

Description:

  An "Entity" object for representing the "Unit" in the ECS system.

Signature:

const entity: Entity

attachAction

Type: Function.

Description:

  Adds a new "UnitAction" to the "Unit" with the specified name, and returns the new "UnitAction".

Signature:

attachAction: function(self: Unit, name: string): UnitAction

Parameters:

ParameterTypeDescription
namestringThe name of the new "UnitAction".

Returns:

Return TypeDescription
UnitActionThe newly created "UnitAction".

removeAction

Type: Function.

Description:

  Removes the "UnitAction" with the specified name from the "Unit".

Signature:

removeAction: function(self: Unit, name: string)

Parameters:

ParameterTypeDescription
namestringThe name of the "UnitAction" to remove.

removeAllActions

Type: Function.

Description:

  Removes all "UnitAction" objects from the "Unit".

Signature:

removeAllActions: function(self: Unit)

getAction

Type: Function.

Description:

  Returns the "UnitAction" with the specified name, or nil if the "UnitAction" does not exist.

Signature:

getAction: function(self: Unit, name: string): UnitAction

Parameters:

ParameterTypeDescription
namestringThe name of the "UnitAction" to retrieve.

Returns:

Return TypeDescription
UnitAction or nilThe "UnitAction" with the specified name, or nil.

eachAction

Type: Function.

Description:

  Calls the specified function for each "UnitAction" attached to the "Unit".

Signature:

eachAction: function(self: Unit, func: function(UnitAction))

Parameters:

ParameterTypeDescription
funcfunctionA function to call for each "UnitAction".

start

Type: Function.

Description:

  Starts the "UnitAction" with the specified name, and returns true if the "UnitAction" was started successfully.

Signature:

start: function(self: Unit, name: string): boolean

Parameters:

ParameterTypeDescription
namestringThe name of the "UnitAction" to start.

Returns:

Return TypeDescription
booleanTrue if the "UnitAction" was started successfully, false otherwise.

stop

Type: Function.

Description:

  Stops the currently running "UnitAction".

Signature:

stop: function(self: Unit)

isDoing

Type: Function.

Description:

  Returns true if the "Unit" is currently performing the specified "UnitAction", false otherwise.

Signature:

isDoing: function(self: Unit, name: string): boolean

Parameters:

ParameterTypeDescription
namestringThe name of the "UnitAction" to check.

Returns:

Return TypeDescription
booleanTrue if the "Unit" is currently performing the specified "UnitAction", false otherwise.