EntitySystem
Extends:
Manages entities on scene.
Example:
const system = new EntitySystem();
class Hello extends Component { constructor() { this.hello = null; } onAction(name) { console.log(name); } }
system.registerComponent('Hello', () => new Hello());
system.root = system.buildEntity({ name: 'hey', components: { Hello: { hello: 'world' } } });
system.updateTransforms();
system.performAction('hi');
Constructor Summary
| Public Constructor | ||
| public |
constructor(triggerEvents: boolean) Constructor. |
|
Member Summary
| Public Members | ||
| public get |
|
|
| public set |
|
|
| public get |
|
|
Method Summary
| Public Methods | ||
| public |
buildEntity(data: *): Entity Build entity from JSON data. |
|
| public |
createComponent(typename: string, properties: *): Component Create component instnace by it's type name and apply properties to it. |
|
| public |
dispose() Destructor (dispose internal resources). |
|
| public |
performAction(name: string, args: *) Perform action on root entity. |
|
| public |
registerComponent(typename: string, componentConstructor: Function) Register new component factory. |
|
| public |
unregisterComponent(typename: string) Unregister component factory. |
|
| public |
Update entities transforms. |
|
Inherited Summary
| From class System | ||
| public static get |
|
|
| public static get |
systems: * |
|
| public static |
dispose() Dispose and remove all registered systems. |
|
| public static |
Returns system instance of given type name. |
|
| public static |
Register new system instance under given name. |
|
| public static |
unregister(typename: string): System Unregister given system. |
|
| public |
dispose() Destructor (disposes all internal resources). |
|
| public |
Event called after system gets registered. |
|
| public |
Event called before system gets unregistered. |
|
Public Constructors
Public Members
Public Methods
public buildEntity(data: *): Entity source
Build entity from JSON data.
Params:
| Name | Type | Attribute | Description |
| data | * | JSON representation of serialized entity data. |
Example:
class Hello extends Component { constructor() { this.hello = null; } }
system.registerComponent('Hello', () => new Hello());
const entity = system.buildEntity({ name: 'hey', components: { Hello: { hello: 'world' } } });
const hello = entity.getComponent('Hello');
console.log(hello.hello);
public createComponent(typename: string, properties: *): Component source
Create component instnace by it's type name and apply properties to it.
Params:
| Name | Type | Attribute | Description |
| typename | string | Component type name. |
|
| properties | * | Object with key-value pairs of component properties. |
Example:
class Hello extends Component { constructor() { this.hello = null; } }
system.registerComponent('Hello', () => new Hello());
const hello = system.createComponent('Hello', { hello: 'world' });
console.log(hello.hello);
public dispose() source
Destructor (dispose internal resources).
Override:
System#disposeExample:
system.dispose();
system = null;
public performAction(name: string, args: *) source
Perform action on root entity. Actions are events that are performed by entity components and are passed down to it's children.
Params:
| Name | Type | Attribute | Description |
| name | string | action name. |
|
| args | * | Action arguments. |
Example:
class Hi extends Component { onAction(name, what) { if (name === 'hi') console.log(what); } }
system.registerComponent('Hi', () => new Hi());
system.root = system.buildEntity({ components: { Hi: {} } });
system.performAction('hi', 'hello');
public registerComponent(typename: string, componentConstructor: Function) source
Register new component factory.
Example:
class MyComponent extends Component { static factory() { return new MyComponent(); } }
system.registerComponent('MyComponent', MyComponent.factory);
