Beginner • Lesson 1

Overview & Quick Start

Maverick Game Engine is a pure TypeScript 2D and isometric 2.5D browser canvas game engine. Zero React or UI framework lock-in—just strongly-typed OOP classes, deterministic fixed-step simulation, and HTML5 Canvas 2D.

1. Install

npm install maverick

2. Your First Game

Every game subclasses Game and implements lifecycle hooks: onReady(), onUpdate(timeDelta), onDraw(timeDelta, perf), and onDisengaged().

import { Game, type SystemPerformance } from 'maverick';

class HelloGame extends Game {
  onReady(): void {
    this.Logger.info('Game ready!');
  }

  onDisengaged(): void {
    this.Logger.info('Cleaned up!');
  }

  onUpdate(_timeDelta: number): void {
    // Fixed-step simulation logic (in seconds)
  }

  onDraw(_timeDelta: number, perf: SystemPerformance): void {
    this.Viewport.clear();
    this.Viewport.drawText(
      `Hello Maverick (${perf.fps} FPS)`,
      { x: 24, y: 32 },
      this.Fonts.get('default')
    );
  }
}

const root = document.getElementById('game-root');
if (root) {
  const game = new HelloGame({
    name: 'HelloWorld',
    viewport: { width: 480, height: 320, fps: 60, bgColor: '#0f172a', showPerfStats: true },
  });
  game.mount(root);
}
Lifecycle & Cleanup: Call game.pause() to pause/unpause simulation, or game.unmount() to stop the loop, release DOM listeners, and remove any auto-created canvas.

3. Core Managers on Game

PropertyResponsibility
game.ViewportCanvas 2D context, DPR scaling, Camera2D, drawing, wrapped text
game.ElementsFlat GameElement registry (for single-scene games)
game.ScenesMulti-scene switching (SceneManager)
game.SpritesImage loading (preload) and spritesheet sub-rectangles
game.InputAction-mapped keyboard & mouse input
game.UIRetained in-canvas UI widgets (UIButton, UIPanel, etc.)
game.SoundsWeb Audio buses (master, sfx, music)
game.Timers / game.TweensPause-aware timers and property tweening