new EntityStore(opts)
- Source:
Centralized place for registering, creating and reusing entities.
For internal use only!
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object |
Properties
|
Members
(private) _factories :Object
- Source:
Object with factories for entity types.
Type:
- Object
(private) _pools :Object
- Source:
Object with different pool for each entity type.
Entity type is a key and Pool
instance is a value.
Type:
- Object
game :Entropy
- Source:
Game instance injected to constructor.
Type:
Methods
create(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 |
Returns:
new (or reused) entity ready to be added to engine
- Type
- Entity
free(entity)
- Source:
Frees entity. Entity is added to the pool. Marks entity as recyceled.
This method is called internally by the engine, user should not call it.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Entity | entity |
register(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
|
registerMany(descriptiors)
- Source:
Registeres many entities.
Parameters:
Name | Type | Description |
---|---|---|
descriptiors |
Array | array of entity's descriptors (see |