Skip to content

0004. 2D rendering: PixiJS behind our own renderer interface

  • Status: Accepted
  • Date: 2026-11-26
  • Phase: 1

Phase 1 needs WebGL 2D with sprite batching, sprite-sheet animation, tilemaps, parallax and particles at 60 fps on a mid-range laptop. We must not write an engine from scratch, and we must be able to swap the renderer later.

Use PixiJS (current major, WebGL 2 with WebGPU option) as the 2D rendering backend, wrapped in @ludrel/render-2d. Game code talks only to our Renderer2D interface and to ECS components (Sprite, AnimatedSprite, TilemapLayer, ParallaxLayer, ParticleEmitter). Only the adapter package imports PixiJS. Our core owns the game loop, scenes and ECS; PixiJS is used purely as a scene-graph renderer (its ticker is disabled). Tilemaps render through a chunked mesh/@pixi/tilemap-style approach.

Option Pros Cons
Phaser Complete, popular, many examples A whole engine with its own loop, scenes, physics and input — it would be our framework, not a part of it; hard to wrap and swap
Hand-written WebGL batcher Smallest bundle, full control Months of work on solved problems (text, filters, masks, context loss)
Three.js for 2D too One renderer for 2D and 3D Larger bundle; 2D niceties (sprite batching, bitmap text) are weaker
Babylon.js 2D — 2D is an afterthought
Canvas 2D Simple Too slow for many sprites and particles

PixiJS adds a noticeable chunk of the runtime (it is modular; we import only what we use and track it with size-limit). Major version upgrades of PixiJS are contained to one adapter package. A headless stub renderer implements the same interface so games can run in Node for tests and the MCP run tool.