Entropy

Entropy

new Entropy(config)

Source:

Main framework factory method. This is the only factory, that needs to be called by user.

Example
const game = Entropy() // creating game with default configuration
game.addEntity('Ball', {
  x: 0,
  y: 0,
})
Parameters:
Name Type Description
config Object
Properties
Name Type Description
pauseOnVisibilityChange Boolean

Extends

Members

(private) _events :Object

Source:
Inherited From:

Object with registered event listeners. Keys are event names.

Type:
  • Object

component :ComponentStore

Source:

Stores components for later reuse.

Type:

engine :Engine

Source:

Instance of Engine.

Type:

entity :EntityStore

Source:

Stores entities for later reuse.

Type:

(private) system :SystemStore

Source:

Stores entities for later reuse.

Type:

ticker :Ticker

Source:

Instance of Ticker class.

Type:

Methods

addEntity(typeOrEntity, …args)

Source:

Adds (or schedules adding) entity to engine. If first argument is entity type (string), then entity instance is created and then added.

Parameters:
Name Type Attributes Description
typeOrEntity Entity | String

entity instance or entity type to create

args Any <repeatable>

arguments passed to onCreate method of entity descriptor, when first argument is entity type

addSystem(typeOrSystem, …args)

Source:

Adds system to engine. If first argument is system type (string), then system instance is created and then added.

Parameters:
Name Type Attributes Description
typeOrSystem System | String

system instance or system type to create

args Any <repeatable>

arguments passed to onCreate method of system descriptor, when first argument is system type

createComponent(type) → {Component}

Source:

Creates new component instance or acquires one from pool.

Parameters:
Name Type Attributes Description
type String

type of component to create

...args Any <repeatable>

arguments passed to onCreate method

Returns:

new (or reused) component ready to add to entity

Type
Component

createEntity(type) → {Entity}

Source:

Creates new entity instance or acquires one from pool.

Parameters:
Name Type Attributes Description
type String

type of entity to create

...args Any <repeatable>

arguments passed to onCreate method

Returns:

new (or reused) entity ready to be added to engine

Type
Entity

createQuery(criterions) → {Query}

Source:

Creates new query from criterions. See Query for details about available criterions.

Parameters:
Name Type Description
criterions Object | Array

criterions

Returns:

query instance

Type
Query

createSystem(type, …args) → {System}

Source:

Creates new entity instance or acquires one from pool.

Parameters:
Name Type Attributes Description
type String

type of system to create

args Any <repeatable>

arguments passed to onCreate method

Returns:

new system ready to be added to engine

Type
System

emit(event, …argopt)

Source:
Inherited From:

Emits event. All listeners attached to this event name earlier will be called with arguments passed after event name.

Parameters:
Name Type Attributes Description
event String

event name

arg Any <optional>
<repeatable>

multiple arguments, that will be passed to listeners

getEntities(query) → {Object}

Source:

Returns entities that matches provided query.

Parameters:
Name Type Description
query Query

query

Returns:

object with length and entities properties

Type
Object

isRunning() → {Boolean}

Source:

Checks if ticker is running.

Returns:
Type
Boolean

off(event, fn)

Source:
Inherited From:

Removes listener for event.

Example
const myHandler = (e) => {}
ee.on('myEvent', myHandler) // handler attached
ee.off('myEvent', myHandler) // handler detached
Parameters:
Name Type Description
event String

event name

fn function

listener function attached earlier

on(event, fn, onceopt)

Source:
Inherited From:

Method used to register event listener.

Parameters:
Name Type Attributes Default Description
event String

event name

fn function

event listener

once Boolean <optional>
false

if set to true, listener will be called once, then it will be unregistered

once(event, fn)

Source:
Inherited From:

Same as EventEmitter#on, bu with implicit once parameter set to true.

Parameters:
Name Type Description
event String

event name

fn function

event listener

pause()

Source:

Pauses the game.

registerComponent(descriptor)

Source:

Registers component.

Example
game.component.register({
  type: 'Position',
  onCreate(x, y) {
    this.x = x;
    this.y = y;
  },
});

const c = game.component.create('Position', 1, 2);
c.x; // 1
c.y; // 2
Parameters:
Name Type Description
descriptor Object

object describing component

Properties
Name Type Description
type String

type of components

onCreate function

method called when component is created

registerComponents(descriptiors)

Source:

Registeres many components.

Parameters:
Name Type Description
descriptiors Array

array of component's descriptors (see ComponentStore#register)

registerEntity(descriptor)

Source:

Registers entity. Entity has to be registered before it can be created.

Example
game.entity.register({
  type: 'Ball',
  onCreate(x, y, texture) {
    const sprite = Sprite(texture);

    this.addComponent('Position', x, y);
    this.addComponent('Sprite', sprite);

    // add sprite to stage for renderer (when using PIXI this has to be done)
    this.game.stage.addChild(sprite);
  },
  onRemove() {
    this.game.stage.removeChild(this.components.sprite.sprite);
  },
});

const c = game.entity.create('Ball', 1, 2, 'ball.png');
Parameters:
Name Type Description
descriptor Object

object describing entity

Properties
Name Type Description
type String

type of entity

onCreate function

method called when entity is created (may be recycled from pool)

onReuse function

method called when entity is reused from pool (called before onCreate)

onRemove function

method called when entity is removed (usually it returns to a pool)

registerEntitys(descriptiors)

Source:

Registeres many entities.

Parameters:
Name Type Description
descriptiors Array

array of entity's descriptors (see EntityStore#register)

registerSystem(descriptor)

Source:

Registers system.

Parameters:
Name Type Description
descriptor Object

object describing system

Properties
Name Type Description
type String

type of system

onCreate function

method called when system is created

onRemove function

method called when system is removed

onUpdate function

method called when system is updated

registerSystems(descriptiors)

Source:

Registeres many systems.

Parameters:
Name Type Description
descriptiors Array

array of system's descriptors (see SystemStore#register)

removeEntity(entity)

Source:

Removes (or schedules removing) entity from engine.

Parameters:
Name Type Description
entity Entity

entity instance

removeSystem(typeOrSystem)

Source:

Removes (or schedules removing) system from engine.

Parameters:
Name Type Description
typeOrSystem System | String

system instance or system type

resume()

Source:

Resumes paused game.

start() → {Boolean}

Source:

Starts the game. See Ticker's Ticker#start method for more details.

Returns:

succesfuly started or not

Type
Boolean

startResponding()

Source:
Inherited From:

Reenables disabled event emitter.

stop(clearEngine) → {Entropy}

Source:

Stops the game. See Ticker's {@ink Ticker@stop} method for more details.

Parameters:
Name Type Description
clearEngine Boolean

if true, engine will be cleared before ticker stop

Returns:

game instance for chaining

Type
Entropy

stopResponding()

Source:
Inherited From:

Disables event emitter so it won't repond to any emitted events.