Beep8 logo

ECS (Entity Component System) Documentation

ECS (Entity Component System) Documentation Source Code

The Entity Component System (ECS) is a design pattern used in game development to manage the complexity of game objects and their behaviors. It separates data (components) from behavior (systems), allowing for more flexible and efficient game architecture.

Ecs Methods

beep8.ECS.add(id, name [,data])

Attach or overwrite a component on an entity.

Parameters

  • id (number): Entity ID
  • name (string): Component name
  • [data] (Object): Component data (stored by reference) (default: {})

beep8.ECS.addSystem(fn)

Register a system that runs every frame.

Parameters

  • fn (Function): System function (dt)=>void

beep8.ECS.addSystemOnce(fn)

Add a system a single time. Don’t overwite existing systems or add multiple copies.

Parameters

  • fn (Function): System function (dt)=>void

beep8.ECS.countByType()

Count entities by type.

beep8.ECS.create(bundle)

Create an entity from a bundle of components.

Parameters

  • bundle (Object.<string, Object>): Keys = component names

Returns

  • (number): The new entity ID

beep8.ECS.entitiesAt(col)

Get all entities at a specific grid location.

Parameters

  • col (number): * @param {number} row

Returns

  • (number[]): Array of entity IDs at that location

beep8.ECS.getComponent(id)

Get one specific component for an entity.

Parameters

  • id (number): * @param {string} name

beep8.ECS.getComponents()

Get the component map for a given component name.

Returns

  • (Map<number,Object>): Map<entityId,data>

beep8.ECS.getEntity()

Return all components for a given entity.

Returns

  • (Map<string, Object>): Map of name → data

beep8.ECS.hasComponent(id)

Check if an entity owns a component.

Parameters

  • id (number): * @param {string} name

beep8.ECS.query()

Query for entities that own all given components.

Returns

  • (number[]): Array of entity IDs

beep8.ECS.removeComponent(id)

Remove a single component from an entity.

Parameters

  • id (number): * @param {string} name

beep8.ECS.removeEntity()

Remove an entity entirely (all its components).

beep8.ECS.removeSystem()

Remove a previously-registered system.

beep8.ECS.reset()

Reset the ECS (clears all entities & components).

beep8.ECS.run(dt)

Run every system in order. Optionally pass a filter: (name)=>boolean

Parameters

  • dt (number): Delta-time in seconds

beep8.ECS.set(id, name, data)

Set a component on an entity, overwriting any existing data. This is a convenience method for add().

Parameters

  • id (number): Entity ID
  • name (string): Component name
  • data (Object): Component data (stored by reference)

beep8.ECS.setLoc(id, col, row)

Set the location of an entity.

Parameters

  • id (number): Entity ID
  • col (number): X tile coordinate
  • row (number): Y tile coordinate

More Beep8 Docs

Actors Documentation

App Intro Documentation

Async Documentation

Cart API

Core Functions

ECS (Entity Component System) Documentation

Game Math Documentation

Game State

Input Documentation

Inventory API

Joystick Documentation

Menu Documentation

Music Documentation

Particle System Documentation

Passcodes Documentation

Public API

Random Numbers Documentation

SFX Documentation

Scene Documentation

Text Renderer

Textmode

Tilemap Documentation

Utilities Documentation