Class: Entity

Class: Entity

Entity

new Entity(engine)

Represents a Entity. Entity is a simple object that holds Component.

Parameters:
Name Type Description
engine Engine

The Engine associated with this object.

Source:

Extends

Members

<private> _engine :Engine

The Engine associated with this object.

Type:
Source:

componentBits :BitSet

The BitSet holding information about what kind of Component this has.

Type:
Source:

componentGroupBits :BitSet

The BitSet holding information about what ComponentGroup this matches.

Type:
Source:

components :Object

The key-value storage of Components.

Type:
  • Object
Source:

id :Number

The ID of this object. This will be given by Engine, and it shouldn't be edited after being added to the Engine. Otherwise, You can edit the value to what you want.

Type:
  • Number
Source:

Methods

<static> fromJSON(engine, data) → {Entity}

Returns new deserialized Entity object.

Parameters:
Name Type Description
engine Engine

the Engine object

data Object

serialized Entity object

Source:
Returns:

the Entity object

Type
Entity

add(key, component)

Adds the Component to the Entity.

Parameters:
Name Type Description
key String

The key of the Component.

component Component

The Component to add.

Source:
Fires:

c(key, args)

Executes Component related functions by its arguments.

If only a key is provided, it returns the Component with that ID. Otherwise, it creates the Component with the options.

Parameters:
Name Type Description
key String

The Component's key

args Object

The options

Source:

create(key, args) → {Entity}

Creates new Component with the args and adds to the Entity.

Parameters:
Name Type Description
key String

The key of the Component.

args Object

A key-value storage to create the Component.

Source:
Returns:

the Entity to allow chains.

Type
Entity

emit(event)

Emits the event. This will trigger all the listener with that event type. You can supply listener function's arguments by appending arguments after the 'event' parameter.

Parameters:
Name Type Description
event String

The name of the event.

args...

Arguments to supply to listeners.

Inherited From:
Source:

get(key) → {Component}

Returns the Component which this Entity has.

Parameters:
Name Type Description
key String

The key of the Component.

Source:
Returns:

The component.

Type
Component

has(key) → {Boolean}

Checks whether if this Entity has the Component.

Parameters:
Name Type Description
key String

The key of the Component to check.

Source:
Returns:

Whether if this Entity has the Component.

Type
Boolean

listeners(event) → {Array}

Returns the array of listeners with specified event type.

Parameters:
Name Type Description
event String

The name of the event.

Inherited From:
Source:
Returns:

An array holding event listeners.

Type
Array

on(event, listener)

Registers a listener.

Parameters:
Name Type Description
event String

The name of the event.

listener function

The function to be triggered.

Inherited From:
Source:

once(event, listener)

Registers a one-time listener. The listener will be removed after being triggered once.

Parameters:
Name Type Description
event String

The name of the event.

listener function

The function to be triggered.

Inherited From:
Source:

remove(key)

Removes the Component from the Entity.

Parameters:
Name Type Description
key String

The key of the Component.

Source:
Fires:

removeAllListeners(event)

Removes all the listener with specified event type. If event parameter is not set, it will remove all the listener of all types.

Parameters:
Name Type Argument Description
event String <optional>

The name of the event.

Inherited From:
Source:

removeListener(event, listener)

Removes the listener.

Parameters:
Name Type Description
event String

The name of the event.

listener function

The function to be removed.

Inherited From:
Source:

toJSON() → {Object}

Serializes the Entity object. Components should be serializable in order to do this.

Source:
Returns:

serialized Entity object

Type
Object

Events

componentAdded

This event is fired when a Component is added to the Entity.

Properties:
Name Type Description
0 Entity

the Entity.

1 String

the Component key added to Entity.

2 Component

the Component added to Entity.

Source:

componentRemoved

This event is fired when a Component is removed from the Entity.

Properties:
Name Type Description
0 Entity

the Entity.

1 String

the Component key removed from the Entity.

Source: