ecs.registerComponent()
ecs.registerComponent({component})
Description
Registers a component with the ECS.
Parameters
component
is an object with the following fields:
Property | Type | Description |
---|---|---|
name | String | The name of the component. Used to call ecs.getAttribute(name) . |
schema | Schema | Data that can be configured on the component. See schema for more information. |
data | Schema | Used for internal bookkeeping, cannot be set from outside the component code. |
schemaDefaults | Object | Optional, contains defaults for each field in schema. |
add | Function | Called once when the component is initialized. See lifecycle methods for more information. |
remove | Function | Called when the component is removed from the entity or when the entity is detached from the scene. See lifecycle methods for more information. |
tick | Function | Called on each render loop or tick of the scene. See lifecycle methods for more information. |
Returns
Returns a handle to the created component.
Example
// Register the component with the ECS
const moveOnSpacebar = ecs.registerComponent({
name: 'moveOnSpacebar',
schema: {
// Specify schema
},
add: (world, component) => {
console.log('hello world')
}
})