LittleJS is 2D and 3D now

79 points by dmit a day ago on hackernews | 25 comments

LittleJS just got the biggest update since it launched! It is still the small, fast, dependency-free HTML5 game engine it always was. Now it also has a full 3D renderer sharing the canvas with your 2D game, built-in level editors, a library of ready-made particle effects, a much faster core, and new tools for making games with AI.

2D and 3D in the same engine

This is the big one! Meshes and shape builders, terrain and voxel maps with collision, shadow maps, colored lights and spotlights, fog, reflections, particles, trails, cameras, and custom shaders on any object. 3D objects are regular LittleJS objects with the same physics, children and timers as 2D, so the two mix freely: a 2D UI over a 3D scene, or a 2D game inside a 3D world.

Prefer Three.js for rendering? There is a plugin for that too!

2D got plenty as well: a new dynamic lighting system, one-way platforms, swept bullet collision, parallax layers, and improved object collision performance.

New Tools

Level editors, 2D and 3D, built into the engine. Press Escape in a debug build to pause the game, edit the level in place with undo, autosave and prefabs, then play on. The editor guide shows how to make them an editor for your own game. 2D levels load and save as Tiled JSON.

Particle effects library. Fire, smoke, sparks, explosions, rain and more, each one line: particleEffect('fire', pos), in 2D or 3D. Every effect takes scale, hue and saturation, and the particle designer tweaks them or builds new ones. Most games will not need anything else.

The example browser has over 100 short examples, each a single file that explains what it shows and how it works, with live editing and a Share button that puts your edited code in a link. It is the best place to learn the engine.

Even Faster

The rendering core was reworked: batched 2D sprites on WebGL2, instanced 3D drawing, and far less per-draw overhead. To measure it I built a WebGL Engine Bench: the same two scenes, moving sprites and lit cubes, through LittleJS, PixiJS, Three.js, PlayCanvas, Phaser and Babylon.js, reporting how many objects each holds at 60 fps.

On my machine LittleJS matched the fastest paths of the other engines and beat them in several. That is one machine and two workloads, so run it on yours: it works in the browser with nothing to install, and results and scene improvements from other engine maintainers are welcome.

Made for AI

LittleJS has a small, well documented API, with the whole thing in one reference file. That is exactly what coding AIs are good at, and it is the same thing that makes it readable for people. So it is now a first-class goal:

  • The LittleJS AI toolkit: starter templates, helper modules and agent instructions for any coding AI, Claude Code, Copilot, Codex or Cursor.
  • The Claude Code plugin installs with two commands. Ask for a game and you get a complete, playable project, engine included, that opens from a file with no server and no npm install. Because the engine already does the rendering, input, physics and audio, the AI’s effort goes into your game.
  • The LittleJS GPT builds games inside ChatGPT with no code at all.
  • The LittleJS Arcade: 50+ small games made this way, all open source, all usable as starters.

Why?

LittleJS was always meant to be a general purpose engine, that I could use for all my games. I started it small on purpose, with js13k as the proving ground, because keeping the core tiny and simple from day one is what makes an engine easy to learn and fast to run.

Everything since has built on that core: people wanted to make more and more ambitious things with it, and what they asked for most was 3D and tools. I wanted the 3D side to feel exactly like the 2D side, same objects, same loop, same small API, not a separate framework bolted on.

The other reason is the community. LittleJS is not a one-person project any more: engine fixes, plugins, examples and a lot of games have come from other people, and the best way to push an engine forward is for people to make things with it. The third LittleJS Game Jam is running right now, October 2 to November 2. Come make something!

Try it!

The new website littlejsengine.com is a demo of all of this: a train ride through every feature, running on the engine.

Thanks for reading! Give us a star oh GitHub if you like the project. 🚂