Intermediate • Lesson 5

Camera2D, TileMaps & Tiled Import

Most games are bigger than one screen. Learn how to move a movie camera across a large world and build levels out of reusable grid tiles—or import them from Tiled & LDtk.

1. World Camera (Camera2D)

Think of beginCamera(cam) and endCamera() like filming with a drone: everything drawn between them scrolls and zooms with the camera, while HUD text drawn after endCamera() stays glued to the screen.

const cam = new Camera2D({ viewportWidth: 560, viewportHeight: 220, zoom: 1.2, followLerp: 0.12 });
cam.followTarget = player;
PoC 1 — Camera2D Smooth Follow & Zoom
Camera2D smoothly tracks the orbiting hero while the HUD stays fixed in place.

2. Orthogonal TileMap & Tiled (.tmj) Import

Instead of typing hundreds of tile IDs by hand, paint your map in Tiled or LDtk and import it with TileMap.fromTiled() or TileMap.fromLDtk().

const map = TileMap.fromTiled(tiledJson, { '1': 'grassTile', '2': 'stoneTile' });
PoC 2 — Importing Tiled JSON into TileMap
Switch between two Tiled JSON layouts imported live via TileMap.fromTiled().