melonjs-loading-assets
Fungsinya
Panduan ini menjelaskan cara mendaftar aset game, memuatnya lebih dulu, dan membacanya kembali, termasuk base path dan layar pemuatan. Panduan ini untuk pengembang game yang mengatur berkas game.
Kapan dipakai
- βSaat seorang pengembang perlu memuat semua gambar dan suara game sebelum layar pertama.
- βSaat seorang pengembang ingin tahu tipe aset mana yang dipakai untuk peta ubin atau font web.
- βSaat aset seorang pengembang gagal dimuat karena alamat web atau pengaturan lintas asal.
Link skill
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-loading-assets/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βSiapkan daftar aset untuk game melonJS saya dengan gambar, peta Tiled, dan folder suara.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill menunjukkan format daftar sumber dengan nama, tipe, dan sumber untuk setiap berkas, lalu menjelaskan cara memuat lebih dulu dan membaca kembali aset.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Apa itu descriptor sumber?
Itu adalah entri dengan nama, tipe, dan jalur sumber untuk satu berkas.
Apakah sumber suara berupa berkas atau folder?
Untuk audio, sumbernya adalah awalan folder, bukan satu nama berkas.
Bisakah saya menyembunyikan layar pemuatan?
Ya. Skill menyebut pengaturan dalam bentuk callback lama yang menekan layar pemuatan bawaan.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 6.4k
- Peringkat
- #14206
- Lisensi
- MIT
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
melonjs-20-migration
6.4kMembantu agent Anda menulis kode game melonJS versi 20 dan menghindari metode yang usang dari versi lama, seperti startup async yang wajib.
melonjs-3d-assets
6.4kMembantu agent Anda memuat model 3D seperti berkas glTF, GLB, dan OBJ ke dalam game browser melonJS, dengan opsi skala dan pencahayaan.
melonjs-3d
6.4kMembantu agent Anda membangun adegan 3D atau 2.5D dalam game browser melonJS, mencakup kamera, mesh, lampu, dan kedalaman, dengan aturan sumbu mesin.
melonjs-audio
6.4kMembantu agent Anda menambahkan efek suara dan musik ke game melonJS, termasuk pengaturan audio, musik latar, kontrol volume, dan suara spasial.
Skill serupa
diffs
394kMemungkinkan agent Anda menghasilkan diff perubahan yang nyata dan dapat dibagikan sebagai tautan viewer atau file gambar, bukan ringkasan yang ditulis manual.
coding-agent
394kMembantu agent Anda menyerahkan pekerjaan pemrograman besar ke Codex, Claude Code, atau OpenCode di latar belakang, lalu memeriksa kemajuannya.
gh-issues
394kMembantu agent Anda menemukan issue GitHub, memilih yang dikerjakan, dan membuka pull request perbaikan, termasuk tindak lanjut komentar tinjauan.