melonjs-getting-started
Qué hace
Explica cómo iniciar un juego de melonJS 20, incluido el paso de configuración obligatorio y cómo añadir los primeros objetos. Va dirigida a desarrolladores que empiezan un juego para navegador nuevo con melonJS.
Cuándo usarla
- ✓Cuando un desarrollador empieza un juego melonJS nuevo y necesita la primera pantalla funcionando.
- ✓Cuando un desarrollador añade objetos pero nunca aparecen en la pantalla.
- ✓Cuando un desarrollador necesita entender qué renderizador usará el juego.
Link de la skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-getting-started/SKILL.mdCópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.
Cómo usar
La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.
Mensaje listo para pegar
Para Claude Code, Codex o Cursor: ejecútalo en la carpeta del proyecto y la skill queda instalada.
Descarga el SKILL.md y ponlo en la carpeta de skills de tu agente.
Ejemplo de qué pedirle a la IA
“Configura un juego básico de melonJS con un texto de título centrado en la pantalla.”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
La skill muestra el orden de configuración: crear la app, esperar a su inicialización con await y luego añadir objetos al contenedor del mundo. También explica el respaldo del renderizador.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de 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
Preguntas frecuentes
¿Por qué no se dibuja nada en mi pantalla?
En la versión 20, la app debe inicializarse con await antes de añadir nada, o los objetos nunca se dibujan.
¿Qué es el contenedor del mundo?
Es donde se añaden los objetos del juego para que aparezcan en pantalla.
¿Qué es el respaldo del renderizador?
El juego usa WebGPU o WebGL 2 cuando están disponibles y recurre a Canvas si no, que carece de algunas funciones.
Detalles
Descripción original del autor
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
Popularidad
- Estrellas en GitHub
- 6,4 mil
- Posición en el ranking
- #14203
- Licencia
- MIT
- Actualizada
- 2/11/2026
Comentarios
- …
Más skills de este repositorio
melonjs-20-migration
6,4 milAyuda a tu agente a escribir código de juegos melonJS para la versión 20 y evitar métodos desactualizados de versiones anteriores, como el arranque asíncrono obligatorio.
melonjs-3d-assets
6,4 milAyuda a tu agente a cargar modelos 3D como archivos glTF, GLB y OBJ en un juego para navegador melonJS, con opciones de escala e iluminación.
melonjs-3d
6,4 milAyuda a tu agente a crear escenas 3D o 2.5D en un juego para navegador melonJS, con cámaras, mallas, luces y profundidad, usando las reglas de ejes del motor.
melonjs-audio
6,4 milAyuda a tu agente a añadir efectos de sonido y música a un juego melonJS, incluida la configuración de audio, las pistas de fondo, el control de volumen y el sonido espacial.
Skills parecidas
diffs
394 milPermite que tu agente genere un diff real y compartible de los cambios, como enlace de visualización o archivo de imagen, en lugar de un resumen escrito a mano.
coding-agent
394 milAyuda a tu agente a pasar un trabajo de programación grande a Codex, Claude Code u OpenCode como trabajador en segundo plano, y después revisar su progreso.
gh-issues
394 milAyuda a tu agente a encontrar incidencias de GitHub, elegir cuáles trabajar y abrir pull requests con correcciones, incluido el seguimiento de los comentarios de revisión.