retro-engine / Exports / Component
The base class inherited by all user-defined components.
Example
An example user-defined component:
class Position extends engine.Component {
static arg_names = ["x", "y"];
static arg_types = [engine.Types.Number, engine.Types.Number];
x;
y;
constructor(x, y) {
this.x = x;
this.y = y;
}
distanceTo(other) {
return Math.sqrt((this.x - other.x) ** 2 + (this.y - other.y) ** 2);
}
}
The constructor can be freely overridden to add any desired arguments, as long as these are reflected in the arg_types
and arg_names
.
• new Component()
• dependencies: any
[] = []
The list of components that this component depends on. E.g. Velocity depends on Position.
The entity that owns this component.
• owner: GameObjectBase
This method is called once the owner of the component has been added to a scene, so some operations can only be performed here rather than in the constructor, for example if you wanted to access the this.owner.scene
property.
▸ onCreate(): void
void
Called when the component is removed, or the owner is deleted.
▸ onDelete(): void
void