Skip to content

Latest commit

 

History

History
101 lines (62 loc) · 2.07 KB

Component.md

File metadata and controls

101 lines (62 loc) · 2.07 KB

retro-engine / Exports / Component

Class: 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);
  }
}

Table of contents

Constructors

Properties

Methods

Constructors

constructor

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()

Properties

dependencies

dependencies: any[] = []

The list of components that this component depends on. E.g. Velocity depends on Position.

Defined in

src/ecs.ts:8


owner

The entity that owns this component.

owner: GameObjectBase

Defined in

src/ecs.ts:9

Methods

onCreate

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

Returns

void

Defined in

src/ecs.ts:24


onDelete

Called when the component is removed, or the owner is deleted.

onDelete(): void

Returns

void

Defined in

src/ecs.ts:26