Saltar al contenido principal

ecs.registerComponent()

ecs.registerComponent({component})

Description

Registers a component with the ECS.

Parameters

component is an object with the following fields:

PropertyTypeDescription
nameStringThe name of the component. Used to call ecs.getAttribute(name).
schemaSchemaData that can be configured on the component. See schema for more information.
dataSchemaUsed for internal bookkeeping, cannot be set from outside the component code.
schemaDefaultsObjectOptional, contains defaults for each field in schema.
addFunctionCalled once when the component is initialized. See lifecycle methods for more information.
removeFunctionCalled when the component is removed from the entity or when the entity is detached from the scene. See lifecycle methods for more information.
tickFunctionCalled 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')
}
})