Intermediate • Lesson 4

Camera2D, TileMaps & 2.5D Isometric

Scroll across large worlds with Camera2D, render chunk-cached TileMap layers, project 2.5D isometric coordinates, and compute shortest paths with GridPathfinder.

1. World Camera (Camera2D)

Wrap world-space rendering between Viewport.beginCamera(cam) and Viewport.endCamera(), while keeping screen-space HUD/UI outside so menus never scroll or zoom with the world.

import { Camera2D } from 'maverick';

const cam = new Camera2D({
  viewportWidth: 480,
  viewportHeight: 320,
  zoom: 1.5,
  bounds: { x: 0, y: 0, width: 1600, height: 1200 },
  followLerp: 0.15,
});
cam.followTarget = player;

// In onUpdate(dt):
cam.update(dt);

// In onDraw(dt):
this.Viewport.clear();
this.Viewport.beginCamera(cam);
map.draw(this.Viewport, this.Sprites, cam);
this.Elements.redrawSorted(this, dt);
this.Viewport.endCamera();
this.UI.draw(this.Viewport);

2. Orthogonal & Isometric TileMap

import { TileMap } from 'maverick';

const map = new TileMap({
  columns: 32,
  rows: 32,
  tileWidth: 64,
  tileHeight: 32,
  orientation: 'isometric',
  tilePalette: { '1': 'grassTile', '2': 'stoneTile' },
});
map.addLayer({ name: 'ground', data: new Array(32 * 32).fill(1) });
map.setTile('ground', 4, 5, 2);

3. 2.5D Isometric Helpers & A* Pathfinding

import { GridPathfinder, isoToWorld, worldToIso } from 'maverick';

const screenPos = worldToIso(3, 2, 16, { tileWidth: 64, tileHeight: 32 });
const gridPos = isoToWorld(screenPos.x, screenPos.y, { tileWidth: 64, tileHeight: 32 });

const path = GridPathfinder.findPath(
  { x: 0, y: 0 },
  { x: 10, y: 8 },
  {
    columns: 32,
    rows: 32,
    allowDiagonal: true,
    isWalkable: (x, y) => map.getTile('ground', x, y) !== 2,
  }
);