โ† Final Day
GAME FEEDBACK

๐Ÿ”Š Audio Mechanics Lab

Sound makes a tiny game feel finished. Learn a few reusable patterns โ€” then add them anywhere.

1 ยท Put the library in your game folder

Your folder might look like this:

my-game/
    index.html
    rbs-game-library.js
    rbs-audio-library.js
    sounds/
        collect.mp3
        hit.mp3
        win.mp3
        music.mp3

Then, just before </body>:

<script src="rbs-game-library.js"></script>
<script src="rbs-audio-library.js"></script>
<script>
    // YOUR GAME CODE HERE
</script>
SET UP ONCE

Make a sound

let collectSound = makeSound(
    "sounds/collect.mp3",
    0.7
);

0 = silent. 1 = full volume.

EVENT

Play it

if (touching(player, coin)) {
    playSound(collectSound);
}

Perfect for collect, jump, hit, unlock and win sounds.

FAST EFFECTS

Allow overlap

playOverlap(
    "sounds/laser.mp3",
    0.5
);

Useful when the same effect may happen again before the previous sound finishes.

MUSIC

Background loop

let music = makeSound(
    "sounds/music.mp3",
    0.25,
    true
);

playSound(music);

Keep music much quieter than effects.

CONTROL

Stop / pause / volume

pauseSound(music);
stopSound(music);
setVolume(music, 0.15);
POLISH

Fade out

fadeOut(music);

Useful at GAME OVER or when changing screens.

Important browser rule

Browsers often block sound that starts automatically before the player has interacted with the page. The safest pattern is: player clicks START โ†’ start music. Sound effects triggered after keyboard, mouse or gamepad interaction are usually much easier.

Sound + haptic = powerful feedback

if (touching(player, gem)) {
    score = changeNumber(score, 1, scoreText);
    playSound(collectSound);
    rumble(0.12, 0.25, 80);
    randomPosition(gem, game);
}

Think in feedback recipes:

Collect โ†’ bright sound + tiny buzz ยท Hit โ†’ heavy sound + strong rumble ยท Win โ†’ success sound + longer rumble.

Challenge

Add three sounds to your game: one action sound, one danger sound and one win sound. Then decide which one should also use haptics.