melonjs-getting-started
What it does
It explains how to start a melonJS 20 game, including the required setup step and how to add the first objects. It is for developers starting a new browser game with melonJS.
When to use it
- βWhen a developer begins a new melonJS game and needs the first working screen.
- βWhen a developer's objects are added but never appear on the screen.
- βWhen a developer needs to understand which renderer the game will use.
Skill link
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-getting-started/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βSet up a basic melonJS game with a centered title text on the screen.β
5 new skills a week. 1 minute to read.
How it works
The skill shows the setup order: create the app, await its initialization, then add objects to the world container. It also explains the renderer fallback.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Getting started with melonJS
Bootstrapping a melonJS 20.x game: the
Applicationlifecycle, the mandatoryawait app.init(), the world container, and what the renderer fallback means for feature availability.
Applies to: melonJS 20.x. Older major versions differ β see the
melonjs-20-migration skill.
The bootstrap
Application construction is synchronous but initialisation is not. init()
returns a promise and must be awaited before building any renderable, loading
assets, or entering a scene.
import { Application, Text } from "melonjs";
const app = new Application(1218, 562, {
parent: "screen", // id of the DOM element to mount into
scale: "auto",
backgroundColor: "#202020",
});
await app.init(); // β REQUIRED. Nothing below works without it.
app.world.addChild(
new Text(609, 281, {
font: "Arial",
size: 160,
fillStyle: "#FFFFFF",
textAlign: "center",
textBaseline: "middle",
text: "Hello World !",
}),
);
This is the single most common thing to get wrong. On 19.x the constructor
called init(width, height, options) for you; on 20.x init() takes no
arguments and calling β and awaiting β it is your job. Nothing that follows
names the missing call. The constructor does build app.world, so adding a
plain renderable succeeds and simply never draws β no canvas is appended and the
app never subscribes to the frame tick β while constructing a Sprite or a
Text throws Cannot read properties of undefined (reading 'renderer'),
because the global game those two fall back on is only set once the first
init() resolves. Either way app.renderer and app.viewport stay undefined
and the page stays blank.
init() is asynchronous because acquiring a WebGPU device is asynchronous. There
is no synchronous alternative.
Top-level await
The bootstrap needs await at module scope. In an ES module that is fine. If the
surrounding tooling does not allow it, wrap it:
async function main() {
const app = new Application(800, 600, { parent: "screen" });
await app.init();
// β¦
}
void main();
Choosing a renderer
video.AUTO (the default) tries WebGPU β WebGL 2 β Canvas and uses the first
that works.
import { video } from "melonjs";
const app = new Application(800, 600, {
parent: "screen",
renderer: video.AUTO, // default; or video.WEBGPU / video.WEBGL / video.CANVAS
});
Two consequences worth knowing before writing rendering code:
- Which backend you get is a runtime fact, not a build-time one. The same code runs on a different renderer depending on the machine. Do not assume WebGL.
- Not every feature exists on every backend. Shader effects and post effects need a programmable pipeline and are inert on Canvas. Where a feature degrades, the engine warns once rather than throwing β so a missing effect is a console warning, not a crash.
Pin the renderer explicitly (video.WEBGL) only when you have a reason to. It
costs you the WebGPU path and the Canvas fallback.
The scene graph
app.world is the root Container. Everything drawn is a descendant of it.
app.world.addChild(sprite, 10); // 10 is the z / draw order
Pass the z-order as the second argument to addChild β it is the only form
that works. renderable.z does not exist as a property, setting depth before
addChild is overwritten by autoDepth, and setting it afterwards does not
resort. See the melonjs-renderables skill for the full explanation.
Scenes
For anything beyond a single screen, use Stage subclasses and the state
manager rather than mutating app.world directly:
import { Stage, state } from "melonjs";
class PlayScreen extends Stage {
onResetEvent() { /* build the scene */ }
onDestroyEvent() { /* tear it down */ }
}
state.set(state.PLAY, new PlayScreen());
state.change(state.PLAY);
onResetEvent runs every time the state is entered, not once β build scene
content there, not in the constructor.
Loading assets
Assets are declared and preloaded through loader; audio needs audio.init()
with the formats you ship before any audio asset is preloaded.
import { audio, loader } from "melonjs";
audio.init("mp3,ogg"); // BEFORE preloading audio
await loader.preload([
{ name: "tileset", type: "image", src: "data/img/tileset.png" },
{ name: "jump", type
FAQ
Why does nothing draw on my screen?
In version 20, the app must be initialized with await before anything is added, or the objects never draw.
What is the world container?
It is where game objects are added so they appear in the game.
What is the renderer fallback?
The game uses WebGPU or WebGL 2 when available and falls back to Canvas, which lacks some features.
Details
Original description by the author
Use this skill when starting or bootstrapping a melonJS game, creating the Application, choosing a renderer, or setting up the first scene. Covers the mandatory async init, the world container, adding renderables, and the WebGPU/WebGL 2/Canvas fallback. Triggers on: melonjs, new Application, app.init, app.world, video.AUTO, video.WEBGL, video.CANVAS, Stage, state.change, getting started, bootstrap.
repo: melonjs/melonJS
Popularity
- GitHub stars
- 6.4k
- Ranking position
- #14203
- License
- MIT
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
melonjs-20-migration
6.4kHelps your agent write melonJS game code for version 20 and avoid outdated methods from older versions, such as the required async startup.
melonjs-3d-assets
6.4kHelps your agent load 3D models such as glTF, GLB and OBJ files into a melonJS browser game, with scale and lighting options.
melonjs-3d
6.4kHelps your agent build 3D or 2.5D scenes in a melonJS browser game, covering cameras, meshes, lights and depth, using the engine's own axis rules.
melonjs-audio
6.4kHelps your agent add sound effects and music to a melonJS game, including audio setup, background tracks, volume control and spatial sound.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.