Sound and music
Turn the sound off
Try playing Hyper Shards with the sound muted. The game still works, but a lot of the feel is gone. The boom, the shard ding and the warning beep were doing real work.
Sound tells players things their eyes miss: a bullet coming from behind, a shard landing, a wave ending. This lesson covers sound effects, music, and how to balance them.
Sound effects are feedback
- ConfirmSomething happened: a laser fired, a shard collected, a plant placed.
- WarnSomething is coming: a rising whine just before the Hyper Shards boss fires.
- RewardYou did well: a short, happy tune when a wave is cleared.
Every important action should have a sound. Keep each effect short, often under half a second, and easy to tell apart from the others.
Quick check
In Garden Defense, a beetle is about to reach Sprig at the edge of the screen. Which sound helps the player most?
- A short warning sound so they look over in time
- Louder background music
- No sound, so the attack is a surprise
Show the answer
A short warning sound so they look over in time
A warning sound is feedback that something is coming. It gives the player a fair chance to react, even when their eyes are busy somewhere else.
How sound gets into a game
A sound file stores a sound wave as a long list of numbers called samples. CD-quality sound uses 44,100 samples every second.
Short effects are often saved as WAV files, which are exact but big. Music is squeezed into MP3 or OGG files, roughly ten times smaller.
One rule surprises many developers: web browsers usually block sound until the player taps, clicks or presses a key. So a web game starts its audio on the first tap, like pressing Play.
Sounds you hear 500 times
In one session, a player might hear the shard ding hundreds of times. Three tricks stop it getting annoying:
- Pitch variationPlay each copy at a slightly different pitch, for example 0.9 to 1.1 times normal speed.
- Several versionsRecord three different pest pops and pick one at random each time.
- A voice limitAllow only a few copies of the same sound at once, maybe 4 to 8, so 30 pops don't become one loud roar.
Bug hunt
1// runs as soon as the page loads2const music = new Audio('garden-loop.mp3');3music.loop = true;4music.volume = 0.4;5music.play();6playButton.onclick = () => {7 startGame();8};
Testers say the Garden Defense music never starts, though Kai hears it on their own laptop. Which line should move inside the Play button's click code?
- Line 2
- Line 3
- Line 5
- Line 7
Show the answer
Line 5
Browsers usually block sound that starts before the player has tapped or clicked. Moving music.play() into the click code starts the music on the first tap. Some browsers relax the rule for sites where you often play sound or video, which is why it worked for Kai.
Music that loops
A wave can last 2 minutes or 20, so game music is usually a loop: a track that plays to the end and jumps back to the start. The spot where it jumps is the loop point. A seamless loop has no gap, click or bump there.
Adaptive music goes further: the track changes with the action. When the Hyper Shards boss arrives, an extra drum layer fades in on top of the same loop.
Players hear every bump each time it repeats, so test loops inside the game.
Making music with Lyria 3.5
The studio's music tool is Lyria 3.5, an AI model from Google that makes music from a text description. We use it inside Google's Flow Music app. A good description covers:
- Mood: calm, tense, cheerful, spooky.
- Tempo: how fast, in BPM (beats per minute).
- Instruments: synths, drums, flute, plucked strings.
- Length: how many seconds, and that it should loop.
Before a track goes into a game we sell, read the tool's latest terms to check that is allowed.
Bolt says: AI music comes out different every time. Ask for three or four versions, test each one inside the game, and change one part of the prompt at a time.
Prompt pick
Remy needs a menu loop for Garden Defense. Which prompt for Lyria 3.5 is most likely to work?
- Make some good music for my game
- Calm, cheerful garden music, about 90 BPM, plucked strings and soft flute, 60 seconds, ending so it loops smoothly to the start
- Loud, fast heavy metal with screaming, as long as possible
Show the answer
Calm, cheerful garden music, about 90 BPM, plucked strings and soft flute, 60 seconds, ending so it loops smoothly to the start
The second prompt names the mood, tempo, instruments and length, and asks for a clean loop. The first gives the AI nothing to go on, and the third does not fit a calm garden menu.
Mixing the levels
Mixing means setting how loud each sound is compared to the others. Music sits underneath, quieter than the effects, so warnings and hits always cut through. Many games also duck the music: they lower it for a moment when an important sound plays, like the boss warning.
Players need control too: separate volume sliders for music and effects, and a mute button. Lots of people play on a phone in a quiet room or on a bus.
Bolt says: Sound is half of game feel. Next lesson: juice, the effects that make every hit feel powerful.
Fact-checked 9 October 2026
- MDN: Autoplay guide for media and Web Audio APIs developer.mozilla.org
- Chrome autoplay policy developer.chrome.com
- Google: Lyria 3.5 in Flow Music blog.google