ComponentStore

ComponentStore

new ComponentStore()

Source:

Module that gathers in one place various operations on components: registering, creating

Methods

create(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

free(component)

Source:

Frees component. Component is added to the pool. This method is called internally by the engine, user should not call it.

Parameters:
Name Type Description
component Component

component

register(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

registerMany(descriptiors)

Source:

Registeres many components.

Parameters:
Name Type Description
descriptiors Array

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