melonjs-audio
यह क्या करती है
यह बताती है कि melonJS गेम में ऑडियो कैसे सेट करें, साउंड कैसे लोड करें और सही ढंग से कैसे चलाएँ। यह ब्राउज़र गेम में ध्वनि जोड़ने वाले गेम डेवलपर्स के लिए है।
कब इस्तेमाल करें
- ✓जब डेवलपर melonJS गेम में साउंड इफ़ेक्ट या बैकग्राउंड संगीत जोड़ना चाहे।
- ✓जब साउंड लोड करते समय डेवलपर को ऑडियो फ़ॉर्मेट की त्रुटि मिले।
- ✓जब डेवलपर चाहे कि वस्तु की जगह के हिसाब से आवाज़ फ़ेड या पैन हो।
Skill का लिंक
https://github.com/melonjs/melonJS/blob/master/packages/melonjs/skills/melonjs-audio/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरे melonJS गेम में जंप का साउंड और लूप होता बैकग्राउंड संगीत जोड़िए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह स्किल AI को पहले ऑडियो फ़ॉर्मेट सेट करने, फिर साउंड फ़ोल्डर पहले से लोड करने, और साउंड इफ़ेक्ट व बैकग्राउंड ट्रैक के लिए अलग कॉल इस्तेमाल करने को कहती है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Audio
Two setup rules
import { audio, loader } from "melonjs";
audio.init("mp3,ogg"); // 1. BEFORE preloading any audio
await loader.preload([
{ name: "cling", type: "audio", src: "data/sfx/" }, // 2. a PREFIX, not a file
]);
audio.init(format)must run before any audio asset is preloaded, and lists the formats you actually ship. Preloading first throwstarget audio extension(s) should be set through me.audio.init() before calling the preloader.It returnsfalsewhen no audio backend is available, so it is worth checking. The format list defaults to"mp3".srcis a prefix, not a file. The loader appends the assetnameplus each configured extension and uses the first that loads — sodata/sfx/+cling+mp3→data/sfx/cling.mp3. Passing a full filename gives you a 404. Adata:audio/...URL is the one exception: it is used verbatim, prefix and extension skipped.
audio.hasAudio() says whether the browser can play audio at all, and
audio.hasFormat("ogg") whether it can play one codec — useful for choosing
the init list or hiding a sound toggle on a device with no audio.
Order matters — melonJS tries the listed formats left to right, so put the
preferred one first. Two formats ("webm,mp3" or "mp3,ogg") is the usual
belt-and-braces for codec coverage. Accepted tokens: mp3, mpeg, opus,
ogg, oga, wav, aac, caf, m4a, m4b, mp4, weba, webm, dolby,
flac.
Effects versus music
audio.play("cling"); // fire and forget
audio.play("cling", false, null, 0.5); // loop, onend, volume
const id = audio.play("engine", true); // looping; keep the id to stop it
audio.playTrack("theme"); // background music
audio.stopTrack();
Use playTrack for music, not play. playTrack(name, volume?) always
loops, and it records the name as the current track — which is what
app.pauseOnBlur / resumeOnFocus / stopOnBlur act on, via
state.pause(true) → pauseTrack(). stopTrack(), pauseTrack(),
resumeTrack() and getCurrentTrack() all read that same single slot, so there
is only ever one current track name.
playTrack stops the track it replaces (20.9.0 and later; before that it
only assigned the slot, and the previous bed kept looping underneath where
stopTrack() could no longer reach it). So a scene just states its own music
and nothing cancels anything:
class PlayScreen extends Stage {
onResetEvent() { audio.playTrack("battle", 0.6); }
}
Calling it with the track already playing restarts it, the same as play()
on any other clip. A scene that wants the bed to carry on across a screen
change should not call it again, rather than rely on it doing nothing.
stopTrack() is for where nothing follows: a scene whose successor has no
music of its own, or a game going quiet. state.change destroys the outgoing
stage before it resets the incoming one, so a stopTrack() in
onDestroyEvent and a playTrack() in the next onResetEvent are in that
order and never cancel each other.
To end a track on an event rather than on a screen change, say a run ending
while the player stays on the same screen, audio.fade(name, from, 0, ms)
takes it down gently. A fade to zero is silence, not a stop, so the voice is
still live until something stops it or replaces it.
Every per-clip function throws audio clip <name> does not exist if the clip was
never loaded, and play additionally throws when a named sprite region is
missing.
Audio sprites
One file carrying many effects, with named regions in milliseconds:
await loader.preload([{
name: "sfx", type: "audio", src: "data/sfx/",
sprite: { jump: [0, 450], hit: [2000, 250], music: [4000, 12000, true] },
}]);
audio.play("sfx", { sprite: "jump" });
A loop with no gap
An MP3 encoder pads the end of its file. Chrome and Firefox trim the padding when they decode it, Safari keeps it, so a looping MP3 has a short silence at every loop there (27 ms on a 12 s clip at 22 kHz, measured). Declare a region of the loop's exact length and loop on that: the voice never reaches the padding.
await loader.preload([{
name: "ambience", type: "audio", src: "data/sfx/",
sprite: { loop: [0, 12000] },
}]);
audio.playTrack("ambience", { sprite: "loop", volume: 0.6 });
// or, as a plain clip: audio.play("ambience", { sprite: "loop", loop: true })
अक्सर पूछे जाने वाले सवाल
ऑडियो लोड करते समय त्रुटि क्यों आती है?
स्किल कहती है कि किसी भी ऑडियो को पहले से लोड करने से पहले ऑडियो फ़ॉर्मेट सेट होने चाहिए।
साउंड का स्रोत फ़ाइल है या फ़ोल्डर?
यह एक प्रिफ़िक्स फ़ोल्डर पथ है, और लोडर नाम और एक्सटेंशन खुद जोड़ता है।
क्या यह जाँच सकती है कि डिवाइस पर ऑडियो काम करता है?
हाँ। यह उन फ़ंक्शन का ज़िक्र करती है जो बताते हैं कि ऑडियो उपलब्ध है और कौन से codec सपोर्ट होते हैं।
जानकारी
लेखक का मूल विवरण
Use this skill for sound and music in melonJS — loading audio, playing effects, background tracks, audio sprites, volume and muting, spatial audio, procedural tone/noise generation, and effects such as reverb or a compressor on the whole mix. Covers the mandatory audio.init format list, the directory-not-file src convention, playTrack versus play, the fixed listener and pixel-scale distances of positional sound, and browser autoplay unlocking. Triggers on: audio, sound, audio.init, audio.play, playTrack, stopTrack, audio.load, sfx, music, volume, mute, fade, rate, pitch, sprite audio, stereo,
repo: melonjs/melonJS
लोकप्रियता
- GitHub स्टार
- 6.4k
- रैंकिंग में स्थान
- #14197
- लाइसेंस
- MIT
- अपडेट की गई
- 2/11/2026
कमेंट
- …
इस repository की और skills
melonjs-20-migration
6.4kआपके एजेंट को melonJS वर्शन 20 के लिए गेम कोड लिखने में मदद करती है और पुराने वर्शन के आउटडेटेड तरीकों से बचाती है, जैसे ज़रूरी async स्टार्टअप।
melonjs-3d-assets
6.4kआपके एजेंट को glTF, GLB और OBJ जैसे 3D मॉडल melonJS ब्राउज़र गेम में लोड करने में मदद करती है, scale और lighting विकल्पों के साथ।
melonjs-3d
6.4kआपके एजेंट को melonJS ब्राउज़र गेम में 3D या 2.5D दृश्य बनाने में मदद करती है, जिसमें कैमरा, मेश, लाइट और गहराई शामिल हैं, इंजन के अपने axis नियमों के साथ।
melonjs-camera-and-drawing
6.4kआपके एजेंट को melonJS गेम का कैमरा नियंत्रित करने में मदद करती है, जैसे खिलाड़ी का पीछा करना, और गेम के अंदर अपने आकार व लाइनें बनाना।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।