melonjs-loading-assets
하는 일
게임의 자산 목록을 작성하고, 미리 로드한 뒤 다시 읽는 방법을 설명합니다. 기본 경로와 로딩 화면도 포함합니다. 게임 파일을 정리하는 개발자를 위한 스킬입니다.
사용하는 경우
- ✓개발자가 첫 화면 전에 게임의 모든 이미지와 사운드를 불러와야 할 때.
- ✓개발자가 타일맵이나 웹 폰트에 어떤 자산 유형을 써야 하는지 알고 싶을 때.
- ✓웹 주소나 교차 출처 설정 때문에 개발자의 자산이 로드되지 않을 때.
스킬 링크
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-loading-assets/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“이미지, Tiled 맵, 사운드 폴더가 있는 제 melonJS 게임의 자산 목록을 설정해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 각 파일의 이름, 유형, 소스를 담은 리소스 목록 형식을 보여 주고, 자산을 미리 로드한 뒤 다시 읽는 방법을 설명합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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
자주 묻는 질문
리소스 디스크립터란 무엇인가요?
파일 하나에 대한 이름, 유형, 소스 경로를 담은 항목입니다.
사운드 소스는 파일인가요, 폴더인가요?
오디오의 경우 소스는 단일 파일 이름이 아니라 폴더 접두사입니다.
로딩 화면을 숨길 수 있나요?
네. 스킬은 이전 콜백 형식에서 내장 로딩 화면을 억제하는 설정을 언급합니다.
상세 정보
작성자의 원본 설명
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
인기도
- GitHub 스타
- 6.4k
- 순위
- #14206
- 라이선스
- MIT
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
melonjs-20-migration
6.4k에이전트가 melonJS 20 버전에 맞는 게임 코드를 작성하고, 필수 비동기 시작 방식 등 이전 버전의 오래된 메서드를 피하도록 돕습니다.
melonjs-3d-assets
6.4k에이전트가 glTF, GLB, OBJ 같은 3D 모델 파일을 melonJS 브라우저 게임에 불러오고, 크기와 조명 옵션을 설정하도록 돕습니다.
melonjs-3d
6.4k에이전트가 melonJS 브라우저 게임에서 카메라, 메시, 조명, 깊이를 포함한 3D 또는 2.5D 장면을 엔진 고유의 축 규칙에 맞게 만들도록 돕습니다.
melonjs-audio
6.4k에이전트가 melonJS 게임에 효과음과 배경 음악을 추가하고, 오디오 설정, 음량 조절, 공간 음향까지 다루도록 돕습니다.