new Component(opts)
- Source:
Describes basic component properties.
For internal use only!
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object |
Properties
|
Members
(private) _componentsIdsMap :Object
- Source:
Stores map of registered types to IDs.
Type:
- Object
Example
{
Position: 0,
Velocity: 1,
...
}
(private) _factories :Object
- Source:
Object with components factories. Factories are created when component is registerd. Type is a key.
Type:
- Object
(private) _greatestComponentId :Number
- Source:
Stores the gratest component's ID so far. Every component type when registered gets it's own unique ID.
Type:
- Number
(private) _id :Number
- Source:
ID of component. Each component type has it's own ID, which is used to identify its bit in entity's bitset.
Type:
- Number
(private) _pools :Object
- Source:
Object with instances of Pool, one for each component type. Type is a key.
Type:
- Object
(private) _propName :String
- Source:
Lowercase component type, which is used to identify component's instance when added to entity.
For type 'Position' propName is position
. For type 'LifeTime' propName is lifeTime
.
Type:
- String
(private) _type :String
- Source:
Type of component.
Type:
- String
Methods
getType()
- Source:
Returns component type.
Returns:
component type
onCreate(optsopt)
- Source:
Run when component is created. Can be overriedden on component registration. Default implementation coppies properties from first argument, if it's an object.
Example
game.component.register({
type: 'Position',
}) // component registered without `onCreate` method
const c = game.component.create('Position', { x: 1, y: 2 }); // default `onCreate` is used
c.x // 1
c.y // 2
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
opts |
Object |
<optional> |
object with proprties to assign to component instance |