Top Related Projects
The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
Cocos2d for Web Browsers. Built using JavaScript.
JavaScript Game Engine
Kiwi.js is a blazingly fast mobile & desktop browser based HTML5 game framework. It uses CocoonJS for publishing to the AppStore.
Quick Overview
melonJS is a lightweight, open-source game engine for HTML5 games. It provides a comprehensive set of tools and features for developing 2D games that run in web browsers, using JavaScript and HTML5 technologies.
Pros
- Easy to learn and use, especially for developers familiar with JavaScript
- Supports both desktop and mobile platforms
- Includes a built-in physics engine and collision detection system
- Active community and regular updates
Cons
- Limited 3D capabilities compared to some other game engines
- Documentation could be more comprehensive for advanced features
- Smaller ecosystem of plugins and extensions compared to larger game engines
- Performance may not be as optimized as some native game engines
Code Examples
- Creating a basic game entity:
game.Entity = me.Entity.extend({
init: function(x, y, settings) {
this._super(me.Entity, 'init', [x, y, settings]);
this.body.setVelocity(3, 15);
this.body.setFriction(0.4, 0);
},
update: function(dt) {
this.body.update(dt);
return true;
}
});
- Adding a simple collision detection:
update: function(dt) {
if (me.collision.check(this)) {
me.collision.response.clear();
}
return true;
}
- Loading and playing audio:
me.audio.load([{
name: "background_music",
type: "audio/mpeg",
src: "data/audio/background_music.mp3"
}]);
me.audio.play("background_music", true);
Getting Started
-
Install melonJS using npm:
npm install melonjs -
Create a basic HTML file:
<!DOCTYPE html> <html> <head> <title>My melonJS Game</title> </head> <body> <div id="screen"></div> <script src="node_modules/melonjs/dist/melonjs.js"></script> <script src="js/game.js"></script> </body> </html> -
Create a
game.jsfile with basic game setup:me.device.onReady(function() { me.video.init(800, 600, {parent: "screen", scale: "auto"}); me.loader.preload([], function() { me.state.set(me.state.PLAY, new PlayScreen()); me.state.change(me.state.PLAY); }); }); -
Run a local server to test your game.
Competitor Comparisons
The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
Pros of PixiJS
- Larger community and more frequent updates
- Better performance for complex graphics and animations
- More comprehensive documentation and examples
Cons of PixiJS
- Steeper learning curve for beginners
- Larger file size, which may impact load times
- Less focus on game-specific features out of the box
Code Comparison
MelonJS:
me.game.world.addChild(me.pool.pull("player", 100, 100));
PixiJS:
const player = new PIXI.Sprite(PIXI.Texture.from('player.png'));
app.stage.addChild(player);
Key Differences
- MelonJS is more focused on game development, while PixiJS is a general-purpose rendering engine
- PixiJS offers more flexibility for custom rendering and effects
- MelonJS provides built-in physics and collision detection, which PixiJS lacks by default
Community and Support
- PixiJS has a larger user base and more third-party plugins
- MelonJS has a smaller but dedicated community focused on game development
Performance
- PixiJS generally offers better performance for complex scenes and particle systems
- MelonJS is optimized for 2D game development and may perform better for simpler games
Learning Resources
- PixiJS has more extensive documentation and tutorials available
- MelonJS provides game-specific examples and guides
Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
Pros of Phaser
- Larger community and ecosystem, with more resources and plugins available
- More comprehensive documentation and tutorials
- Better performance for complex games and large-scale projects
Cons of Phaser
- Steeper learning curve, especially for beginners
- Larger file size, which may impact load times for web games
- More complex setup process compared to MelonJS
Code Comparison
MelonJS:
me.game.onload = function() {
me.state.set(me.state.PLAY, new PlayScreen());
me.state.change(me.state.PLAY);
};
Phaser:
const config = {
type: Phaser.AUTO,
scene: PlayScene
};
const game = new Phaser.Game(config);
Both frameworks use a scene-based approach, but Phaser's configuration is more concise. MelonJS uses a state system, while Phaser uses a scene system. Phaser's setup is more straightforward, but MelonJS offers more flexibility in state management.
Overall, Phaser is better suited for larger, more complex projects with a need for extensive community support and resources. MelonJS is a good choice for simpler games or developers who prefer a more lightweight framework with a gentler learning curve.
Cocos2d for Web Browsers. Built using JavaScript.
Pros of cocos2d-html5
- More comprehensive framework with a wider range of features and tools
- Larger community and ecosystem, providing better support and resources
- Cross-platform compatibility, allowing development for multiple platforms
Cons of cocos2d-html5
- Steeper learning curve due to its complexity and extensive feature set
- Heavier framework, potentially impacting performance on lower-end devices
- Less frequent updates and maintenance compared to melonJS
Code Comparison
melonJS:
me.game.onload = function() {
me.state.set(me.state.PLAY, new PlayScreen());
me.state.change(me.state.PLAY);
};
cocos2d-html5:
var MyScene = cc.Scene.extend({
onEnter: function () {
this._super();
var layer = new MyLayer();
this.addChild(layer);
}
});
Both frameworks use similar concepts for scene management, but cocos2d-html5 employs a more object-oriented approach with class extension. melonJS uses a simpler state-based system, which may be easier for beginners to grasp. However, cocos2d-html5's approach offers more flexibility and power for complex game structures.
JavaScript Game Engine
Pros of Crafty
- More flexible entity-component system, allowing for easier composition of game objects
- Larger and more active community, resulting in more resources and third-party plugins
- Better suited for complex, multi-scene games with its scene management system
Cons of Crafty
- Steeper learning curve due to its unique entity-component architecture
- Less optimized for mobile devices compared to MelonJS
- Documentation can be outdated or incomplete in some areas
Code Comparison
MelonJS:
me.game.world.addChild(me.pool.pull("player", 100, 100));
Crafty:
Crafty.e("2D, Canvas, Color").attr({x: 100, y: 100, w: 50, h: 50}).color("red");
Both frameworks offer different approaches to creating game entities. MelonJS uses a pooling system for object creation, while Crafty employs a more flexible entity creation method with component-based attributes.
MelonJS focuses on simplicity and ease of use, making it ideal for beginners and mobile game development. Crafty, on the other hand, provides more flexibility and power for complex game structures, but may require more time to master.
Ultimately, the choice between these frameworks depends on the specific requirements of your game project and your familiarity with different programming paradigms.
Kiwi.js is a blazingly fast mobile & desktop browser based HTML5 game framework. It uses CocoonJS for publishing to the AppStore.
Pros of Kiwi.js
- More modern architecture with better support for ES6+ features
- Extensive plugin system for easy extensibility
- Better documentation and learning resources
Cons of Kiwi.js
- Smaller community and fewer updates compared to MelonJS
- Less optimized for mobile devices
- Steeper learning curve for beginners
Code Comparison
MelonJS example:
me.game.onload = function() {
me.state.set(me.state.PLAY, new PlayScreen());
me.state.change(me.state.PLAY);
};
Kiwi.js example:
var game = new Kiwi.Game('content', 'MyGame', state, { renderer: Kiwi.RENDERER_WEBGL });
game.states.addState(PlayState);
game.states.switchState("PlayState");
Both frameworks use a state-based approach for game management, but Kiwi.js has a more object-oriented structure. MelonJS uses a global me object, while Kiwi.js creates a game instance. Kiwi.js also explicitly specifies the renderer, offering more flexibility.
MelonJS is generally easier for beginners to pick up, while Kiwi.js provides more advanced features and customization options. The choice between the two depends on the specific needs of your project and your familiarity with JavaScript game development.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
melonJS 2

A modern & lightweight HTML5 game engine

melonJS is an open-source 2D game engine designed for indie developers â post-processing effects, custom shaders, 3D mesh support, polygon-accurate physics, modern Tiled workflows, and high performance, all packed into just over 100 KB minzipped of vanilla JS/TS with no toolchain lock-in. Built with ES6 classes and bundled with esbuild.
melonJS is licensed under the MIT License and actively maintained by the team at AltByte in Singapore.
Why melonJS
melonJS is designed so you can focus on making games, not on graphics plumbing.
-
Canvas2D-inspired rendering API â If you've used the HTML5 Canvas, you already know melonJS. The rendering API (
save,restore,translate,rotate,setColor,fillRect, ...) follows the same familiar patterns â no render graphs, no shader pipelines, no instruction sets to learn. -
True renderer abstraction â Write your game once, run it on WebGL or Canvas2D with zero code changes. The engine handles all GPU complexity behind a unified API, with automatic fallback when WebGL is not available. Designed to support future backends (WebGPU) without touching game code.
-
Complete engine, minimal footprint â Physics, tilemaps, audio, input, cameras, tweens, particles, UI â a full 2D game stack in a single tree-shakeable ES module. No dependency sprawl, no library stitching.
-
Tiled as a first-class citizen â Deep Tiled integration built into the core: orthogonal, isometric, hexagonal and staggered maps, animated tilesets, collision shapes, object properties, compressed formats â all parsed and rendered natively.
-
Batteries included, hackable by design â Get started in minutes with minimal setup. When you need to go deeper: ES6 classes throughout, a plugin system for engine extensions, and a clean architecture that's easy to extend without fighting the framework.
About melonJS
melonJS is a fully featured game engine :
Compatibility
- Standalone library (does not rely on anything else, except a HTML5 capable browser)
- Compatible with all major browsers (Chrome, Safari, Firefox, Opera, Edge) and mobile devices
Graphics
- 2D sprite-based graphic engine
- Fast WebGL renderer for desktop and mobile devices with fallback to Canvas rendering
- Extensible batcher system for custom rendering pipelines
- High DPI resolution & Canvas advanced auto scaling
- Sprite with 9-slice scaling option, and animation management
- Built-in effects such as tinting, masking and 2D lighting (with optional per-pixel normal-map shading on sprites for 3D-looking dynamic lights)
- Standard spritesheet, single and multiple Packed Textures support
- Compressed texture support (DDS, KTX, KTX2, PVR, PKM) with automatic format detection and fallback
- 3D mesh rendering with OBJ/MTL model loading, perspective projection and hardware depth testing
- Built-in shader effects (Flash, Outline, Glow, Dissolve, CRT, Hologram, etc.) with multi-pass chaining via
postEffects, plus custom shader support viaShaderEffectfor per-sprite fragment effects (WebGL) - Trail renderable for fading, tapering ribbons behind moving objects (speed lines, sword slashes, magic trails)
- System & Bitmap Text with built-in typewriter effect
- Video sprite playback
Sound
- Web Audio support with 3D spatial audio and stereo panning based on Howler
Physics
- Polygon (SAT) based collision algorithm for accurate detection and response
- Fast Broad-phase collision detection using spatial partitioning (QuadTree)
- Collision filtering for optimized automatic collision detection
- Multiple shapes per body for complex hitboxes
Input
- Mouse and Touch device support (with mouse emulation)
- Gamepad support with button and axes binding
- Keyboard event handling with key binding system
- Device motion & accelerometer support
Camera
- Multi-camera support (split-screen, minimaps, multiple viewports)
- Camera follow with configurable deadzone and damping
- Built-in shake, fade, flash, and mask-based transition effects
- Per-camera post-processing pipeline with stackable shader effects and color grading (ColorMatrix)
UI
- Clickable, hoverable and draggable UI elements
- Drag-and-drop support
- Text buttons with built-in styling
Level Editor
- Tiled map format up to 1.12 built-in support for easy level design
- Uncompressed and compressed Plain, Base64, CSV and JSON encoded XML tilemap loading
- Orthogonal, Isometric, Hexagonal (both normal and staggered) and Oblique maps
- Multiple layers with per-layer alpha, tinting and blend modes (multiple background/foreground, collision and Image layers)
- Parallax scrolling via Image layers, with parallax origin support
- Animated and multiple Tileset support, tile sub-rectangles, embedded base64 images
- Tileset transparency settings
- Rectangle, Ellipse, Polygon, Polyline and Capsule (round-rect) object shapes
- Tiled Objects with custom properties (string, number, boolean, color, file, object, list/array and class-typed)
- Per-object opacity and visibility
- Concave collision polygons auto-decomposed via earcut triangulation
- Flipped & rotated Tiles
- Dynamic Layer and Object/Group ordering
- Dynamic Entity loading via an extensible object factory registry â register custom handlers for any Tiled class name without modifying engine code
- Shape based Tile collision support
Assets
- Asynchronous asset loading with progress tracking
- A fully customizable preloader
- Support for images, JSON, TMX/TSX, audio, video, binary and fonts
Core
Applicationclass as the modern entry point with built-in pause, resume, andfreeze()(hit-stop) primitives- A state manager (to easily manage loading, menu, options, in-game state)
- Tween effects with multiple easing functions (Quadratic, Cubic, Elastic, Bounce, etc.) and Bezier/Catmull-Rom interpolation
- Transition effects
- Pooling support for object recycling
- Basic Particle System
- EventEmitter based event system
- Persistent data storage (save/load via localStorage)
- Plugin system for extending engine capabilities
Tools integration
melonJS is supporting the below tools and frameworks natively or through our official plugin(s) :
Tools integration and usage with melonJS is documented in our Wiki.
Getting Started
The fastest way to create a new game:
npm create melonjs my-game
cd my-game
npm install
npm run dev
This scaffolds a ready-to-run project with TypeScript, Vite, and the debug plugin. It also works with plain JavaScript â just rename .ts files to .js.
You can also start from the boilerplate directly, or follow the step-by-step Platformer Tutorial.
For more details, check the wiki Details & Usage guide.
Examples
- Platformer (source)
- Isometric RPG (source)
- SVG Shapes (source)
- Graphics (source)
- Hello World (source)
- Whac-A-Mole (source)
- Compressed Textures (source)
- 3D Mesh (source)
- 3D Mesh Material (source)
- Trail (source)
- Shader Effects (source)
- Spine (source)
Browse all examples here
Basic Hello World Example
import { Application, Text } from "https://cdn.jsdelivr.net/npm/melonjs/+esm";
// create a new melonJS application
const app = new Application(1218, 562, {
parent: "screen",
scale: "auto",
backgroundColor: "#202020",
});
// set a gray background color
app.world.backgroundColor.parseCSS("#202020");
// add a font text display object
app.world.addChild(new Text(609, 281, {
font: "Arial",
size: 160,
fillStyle: "#FFFFFF",
textBaseline: "middle",
textAlign: "center",
text: "Hello World !",
}));
Simple hello world using melonJS
Documentation
Plugins
melonJS provides a plugin system allowing to extend the engine capabilities.
Here is the list of official plugins maintained by the melonJS team:
- debug-plugin - a debug panel for inspecting game objects
- tiled-inflate-plugin - enable loading and parsing of zlib, gzip and zstd compressed Tiled maps
- spine-plugin - Spine runtime integration to render Spine skeletal animations
If you wish to develop your own plugin, we also provide a plugin template to help you get started.
Installation
melonJS is distributed as a tree-shakeable ES6 module with TypeScript declarations included.
Install via npm :
npm install melonjs
Then import what you need in your project :
import { Application, Sprite, loader } from 'melonjs';
Or use it directly via jsDelivr CDN :
<!-- load the ES6 module bundle of melonJS v19.x -->
<script type="module" src="https://cdn.jsdelivr.net/npm/melonjs@19/+esm"></script>
<!-- omit the version completely to get the latest one -->
<!-- you should NOT use this in production -->
<script type="module" src="https://cdn.jsdelivr.net/npm/melonjs/+esm"></script>
Note: the debug plugin is available separately as
@melonjs/debug-plugin
Community
Join us and get help or share your projects :
Contributing
We welcome contributions! Please read our Contributing Guide before submitting changes or new features.
Sponsors
Support the development of melonJS by becoming a sponsor. Get your logo in our README with a link to your site or become a backer and get your name in the BACKERS list. Any level of support is really appreciated and goes a long way !
Top Related Projects
The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
Cocos2d for Web Browsers. Built using JavaScript.
JavaScript Game Engine
Kiwi.js is a blazingly fast mobile & desktop browser based HTML5 game framework. It uses CocoonJS for publishing to the AppStore.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot




