The Game class is the core entry point for creating and managing a game instance.
It serves as a central hub that coordinates all game systems including scenes, entities, components, and various managers (rendering, physics, input, etc.).
The class provides methods to initialize the game with custom configuration, add scenes and dependencies, and control the game loop execution.
Through dependency injection, it ensures proper initialization and communication between all game systems.

// Basic game setup with minimal configuration
const game = new Game({
containerNode: document.getElementById("app"),
width: 1920,
height: 1080,
});
game.addScene(MainScene, "MainScene");
game.start();
// Advanced game setup with custom physics and collision settings
const game = new Game({
containerNode: document.getElementById("app"),
width: 1920,
height: 1080,
debugEnabled: false,
canvasColor: "#000000",
physicsFramerate: 180,
collisions: {
collisionMatrix: [
["layer1", "layer2"],
["layer1", "layer3"],
],
collisionMethod: CollisionMethods.SAT,
collisionBroadPhaseMethod: BroadPhaseMethods.SpartialGrid,
}
});
game.addScene(MainScene, "MainScene");
game.start();

Constructors

Accessors

  • get running(): boolean
  • TRUE if the game is running

    Returns boolean

Methods

  • Add a new instance to be used as dependency

    Parameters

    • dependencyInstance: any

      The dependency instance

    • name: DependencyName

      The name for the dependecy

    Returns void

  • Add a new class to be used as dependency

    Parameters

    • dependencyType: DependencyType

      The class of the dependency

    • Optionalname: DependencyName

      The name for the dependecy (optional: if the class uses the "injectable" decorator, this parameter is unnecesary)

    Returns void

  • Add a scene to the game

    Parameters

    • sceneType: SceneType

      The class of the scene

    • name: string

      The name for the scene

    • openingScene: boolean = false

      If this is the opening scene, set TRUE, FALSE instead (optional: default FALSE)

    Returns void

  • Start the game

    Returns void

  • Stop the game

    Returns void