LittleJS - The Tiny JavaScript Game Engine That Can
All aboard!
LittleJS is a super lightweight JavaScript game engine with a fast hybrid rendering system. It provides a comprehensive set of tools including rendering, physics, particles, sound effects, music, input handling, and debug tools. The code is very clean and well documented with a variety of examples to get you started. Choo-Choo!
Examples
Starter Project - Clean demo with only a few things to get you started
Puzzle Game - Match 3 puzzle game with HD rendering and high score tracking
Platformer - Platformer/shooter with procedural generation and destruction
Breakout - Breakout game with post processing effect
Stress Test - Max sprite/object test and music system demo
Particle System Designer - Particle system editor and visualizer
Features
- Very small footprint with no dependencies
- Can update and render 10,000+ objects at 60fps, often many times more
- Object oriented system with fast 2D physics and collision handling for axis aligned boxes
- Positional audio effects with ZzFX and music with ZzFXM, mp3s, or wavs
- Input processing system with keyboard, mouse, gamepad, and touch support
- Particle effects system (particle editor/designer in progress)
- Medal system tracks and displays achievements with Newgrounds integration
- Several easy to understand example projects you can build on
- Apply Shadertoy compatible shaders for post processinge effects
- Debug tools and debug rendering system
- Full documentation automatically generated from the source code block tags with JSDoc
- Build system automatically combines everything, minifies, and removes unused code
- For size coding competitions like js13kGames, starter project builds to a 7KB zip file
- Easily build a Windows executable with Electron for distribution on platforms like Steam
- Open Source with the MIT license so it can be used for anything you want
- Can be imported as a JavaScript module and includes an example module project
- Compatible with TypeScript and includes an example TS project
Builds
To easily include LittleJS in your game, you can use one of the 3 pre-built js files. These are also built automatically by the build scripts.
- littlejs.js - The full game engine with debug mode available
- littlejs.release.js - The engine optimized for release builds
- littlejs.min.js - The engine in release mode and minified
LittleJS can also be imported as a module. There are two module flavors that are automatically built.
- littlejs.esm.js - The engine exported as a module with debug mode available
- littlejs.esm.min.js - The engine exported as a minified module in release mode
There is an enginebuild.bat file included that will rebuild the engine files. The starter project example also includes a batch file build.bat that compresses everything into a tiny zip file using Google Closure, UglifyJS, Roadroller, and ECT. You must first run npm install to setup the necessary npm dependencies.
Tutorial
- Breakout Tutorial - Shows how to make a simple game from scatch with LittleJS.
Debugging
Debug builds of LittleJS have a special menu that can be opened by pressing ~, the tilde key.
- ~: Debug Overlay
- 1: Debug Physics
- 2: Debug Particles
- 3: Debug Gamepads
- 4: God Mode
- 5: Save Screenshot
Simple Code
This engine is made with simplicity in mind using simple and easy to read code. There are only a few files used by the entire engine.
- engine.js - Top level engine init, update, and render
- engineSettings.js - Global engine settings
- engineObject.js - Base object class and physics
- engineDraw.js - Code for canvas drawing and text
- engineAudio.js - Spacial sound effects, and zzfx sound generator
- engineInput.js - Input for keyboard, mouse, touch, and gamepad
- engineUtilities.js - Vector2, Color, and Timer clases and math functions
Optional Components, these components are built to synergize with the rest of the engine but are not necessary.
- engineTileLayer.js - Tile layer rendering and collision
- engineParticles.js - Particle system with fast rendering and collision
- engineWebGL.js - Super fast rendering with WebGL and post processing
- engineMedals.js - Achievement tracker with Newgrounds integration
- engineDebug.js - Debug rendering system and information overlay
Games Made With LittleJS
Here are a few of the amazing games people are making with LittleJS.
- Space Huggers - Run and gun platformer with procedural levels
- Undergrowth - An interactive music videogame for the band Squid
- Space Huggers - JS13K Edition - Original js13k game with source code
- Isletopia - Relaxing strategy game of greenifying barren islands
- Dead Again - Top down survial horror by sanojian & repsej
- Hel's Trial - Turn based RPG by Sebastian Dorn
- Bit Butcher - Survival crafting game by Deathray Games
- Necrotic Commander - Tower defense game by Daniel Jeffery
- Boxing up Bamboo - A challenging puzzle game by Patrick Traynor
- Send me your games!