Beginner • Lesson 1

Overview & Quick Start

A web browser is built to display documents and buttons—not 60-frames-per-second video games. Maverick gives you a blank digital painting board (an HTML5 <canvas>) and a heartbeat (a game loop) so you can build 2D and 2.5D games without fighting browser quirks or UI frameworks like React.

Think of it like a flipbook movie: A game is just a fast flipbook. Every 1/60th of a second, Maverick does two jobs in order: first it calculates where everything moved (onUpdate), and then it paints the new picture onto the screen (onDraw).

Without a Game Engine

If you use raw browser timers like setInterval or requestAnimationFrame by hand, a player on a 144Hz monitor runs twice as fast as someone on a 60Hz laptop. Switching browser tabs causes huge time jumps that teleport characters through walls, blurry pixels appear on Retina screens, and leaving a page leaks keyboard listeners.

Why Maverick Built Game

Game locks your game's math to a steady fixed-step clock (so gameplay speed is identical on every monitor), automatically scales crisp pixels for high-DPI screens (DPR scaling), caps lag spikes so characters don't teleport, and cleans up every listener when you call unmount().

1. Install

npm install maverick

2. Your First Game & The 4 Lifecycle Hooks

To make a game, you create a class that extends Game. Maverick calls four special methods (called lifecycle hooks) at the exact right moments—just like a theater stage manager:

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.
Live Proof of Concept — HelloGame Lifecycle
Initializing Maverick Game...

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