melonjs-loading-assets
Qué hace
Explica cómo listar los recursos de un juego, precargarlos y leerlos después, incluidas las rutas base y las pantallas de carga. Va dirigida a desarrolladores de juegos que organizan los archivos del juego.
Cuándo usarla
- ✓Cuando un desarrollador necesita cargar todas las imágenes y sonidos de un juego antes de la primera pantalla.
- ✓Cuando un desarrollador quiere saber qué tipo de recurso usar para un mapa de teselas o una fuente web.
- ✓Cuando los recursos de un desarrollador no se cargan por una dirección web o un ajuste de origen cruzado.
Link de la skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-loading-assets/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 la lista de recursos de mi juego de melonJS con imágenes, un mapa de Tiled y una carpeta de sonidos.”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
La skill muestra el formato de la lista de recursos, con un nombre, un tipo y una ruta de origen para cada archivo, y luego explica cómo precargarlos y leerlos después.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de GitHub.
Loading assets
The resource descriptor
Every asset is { name, type, src } plus type-specific extras:
import { loader } from "melonjs";
await loader.preload([
{ name: "tiles", type: "image", src: "data/img/tiles.png" },
{ name: "map1", type: "tmx", src: "data/map/map1.tmx" },
{ name: "tileset", type: "tsx", src: "data/map/tileset.tsx" },
{ name: "sfx", type: "audio", src: "data/sfx/" },
{ name: "font", type: "fontface", src: "data/font/PressStart2P.ttf" },
{ name: "atlas", type: "json", src: "data/img/atlas.json" },
]);
preload() has been awaitable since 19.8. The callback form still works and
takes a third argument to suppress the built-in loading screen:
loader.preload(resources, onLoaded, /* switchToLoadState */ false);
The type list
The type strings are melonJS-specific — this is not a generic loader:
| type | for |
|---|---|
"image" |
textures, sprite sheets, normal maps |
"json" |
data, texture-atlas descriptors, collision shapes from a shape editor |
"tmx" / "tsx" |
Tiled maps and external tilesets |
"audio" |
sound — src is a directory, see below |
"video" |
video textures |
"binary" |
raw data, bitmap font .fnt descriptors |
"fontface" |
web fonts (.ttf, .woff) |
"aseprite" |
Aseprite JSON + image |
"shader" |
GLSL/WGSL shader sources — src or inline via data |
"obj" / "mtl" |
Wavefront models and materials |
"gltf" / "glb" |
glTF scenes |
"js" |
scripts |
| any type you register | your own formats, and things you generate rather than download — see Custom asset types |
What belongs in the manifest — and what cannot
Preloading is not only for things with a URL. Three tiers, and the middle one is the one people miss.
After preloading, switch to a stage of your own. preload() puts you in
state.LOADING, and that stage is transitional: build your scene in the
callback and stay there, and nothing ever destroys it, so the built-in loading
screen's logo and progress bar remain on top of your game. See
melonjs-scenes-and-state.
1. Assets with a source. Everything in the type table above. Note "shader"
takes inline source as well as a src, via the data field:
import { myRamp } from "./myRamp"; // a GLSL fragment body, in your own module
loader.preload([
{ name: "ramp", type: "shader", data: myRamp },
]);
const fx = loader.getShader("ramp"); // shared, already compiled
This matters more than it looks. A ShaderEffect compiles its program in its
constructor, and compileProgram calls getProgramParameter(LINK_STATUS)
immediately after linkProgram — a blocking call that forces the driver to
finish. So building one during a scene costs that link on the frame it appears,
and building three identical ones costs it three times. Preloaded as an asset it
is compiled at load time, behind the loading screen, and the loader hands out a
shared instance (effect.shared === true), which is what stops one
renderable's teardown freeing it out from under the others. clone() does NOT
help here — it constructs a new effect, and therefore links a new program.
2. Derived assets — build once, before the first stage. Canvases you bake,
NoiseTexture2d, TextureAtlas: none of the built-in types describes these,
and they must not be rebuilt per scene either. The renderer's texture cache is
keyed by the image object, so a freshly baked canvas is a brand new GPU
texture with a new mip chain — rebuild one per stage and a title → play →
game-over cycle uploads four copies of the same pixels. Build each once and
share it from a module the scenes read from, the way the platformer example
builds its TextureAtlas.
Where you build it depends on what it costs. A gradient or a palette strip is
well under a millisecond: build it after preload resolves. A bake that takes
real time — procedural noise is the usual one: Earth Defender's sky, two fractal
simplex fields over a 512² tile, takes about 200ms on a desktop — belongs
inside the preload as an asset type of your
own (Custom asset types). It then runs behind the loading
screen and counts on the progress bar. Built on stage entry instead, it lands on
the frame the scene is assembled, and with a transition running that frame is a
black screen.
**3. The engine's own shader programs — warmed for you, si
Preguntas frecuentes
¿Qué es un descriptor de recurso?
Es una entrada con un nombre, un tipo y una ruta de origen para un archivo.
¿La fuente de sonido es un archivo o una carpeta?
Para el audio, el origen es un prefijo de carpeta, no un nombre de archivo.
¿Puedo ocultar la pantalla de carga?
Sí. La skill menciona un ajuste en la forma antigua de callback que suprime la pantalla de carga integrada.
Detalles
Descripción original del autor
Use this skill for loading and managing game assets in melonJS — the resource descriptor format, the full asset type list, preload versus load, retrieving loaded assets, base URLs and cross-origin settings, and the loading screen. Triggers on: loader, loader.preload, loader.load, resources, getImage, getJSON, getTMX, getGLTF, getVideo, getFont, setBaseURL, setOptions, crossOrigin, withCredentials, credentials, cookies, authenticated assets, CORS, asset, preload, LOADER_COMPLETE, loading screen, unload, setParser, custom asset type, generated texture, procedural texture.
repo: melonjs/melonJS
Popularidad
- Estrellas en GitHub
- 6,4 mil
- Posición en el ranking
- #14206
- 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.