Concepts

API shape

Understand Game ownership, class-based services, and resource lifecycle.

BornEngine uses a class-first TypeScript API. Extend Game to keep startup, simulation, and rendering with the services they use. The runtime exposes renderer, input, audio, scenes, and sceneGraph on the same instance. Resource constructors receive that owner so the engine can validate ownership and release native state safely.

typescript
import { Colors, Game, Texture } from '@bornengine/engine';

class SpriteGame extends Game {
  private readonly player: Texture;

  constructor() {
    super({ window: { title: 'Sprite demo' } });
    this.player = new Texture(this, 'assets/player.png');
  }

  protected override onStart(): void {
    // Prepare game-specific systems here.
  }

  protected override loop(deltaTime: number): void {
    // Move the player by deltaTime, measured in seconds.
  }

  protected override render(): void {
    this.renderer.clear(Colors.BLACK);
    if (this.player.isLoaded) this.player.draw({ x: 100, y: 120 });
  }
}

new SpriteGame().run();

run() calls onStart once, then loop(deltaTime) and render() for each frame. When the game stops, onStop() runs before the runtime disposes its owned resources. Use run({ update, render, onStop }) when callback composition is a better fit; the callback form keeps the same owner and explicit resource lifetimes.

Ownership

A Game is the root owner for one engine context. Today the native runtime is process-global, so only one active Game can run at a time. Services and resources created for another game are rejected instead of silently crossing runtime boundaries.

Classes and values

Stateful engine objects use classes: Texture, Sound, Model, PhysicsWorld, SceneNode, and ColyseusClient keep context and lifecycle alongside their operations. Value-only data such as Vec3, colors, rectangles, and camera descriptions stays plain or uses small math classes. This makes ownership visible without forcing value data into runtime objects.

Public imports

Import from @bornengine/engine for the common application surface, or use documented subpaths such as @bornengine/engine/physics and @bornengine/engine/colyseus. Those barrels expose the supported TypeScript API. Native operation declarations and numeric handle registries are internal implementation details.

See the Game API for gameplay lifecycle and core API for the frame owner.