Skip to main content

Step 15 - Flappy Sounds and Music

Finally to really add depth to a game let's add some sound! ex.Sound needs to be loaded much like ex.ImageSource.

Excalibur supports any audio your browser supports, you can specify an ordered list of files to fallback to if a browser doesn't support.

typescript
// resources.ts
export const Resources = {
// Relative to /public in vite
...
// Sounds
FlapSound: new ex.Sound('./sounds/flap.wav'),
FailSound: new ex.Sound('./sounds/fail.wav'),
ScoreSound: new ex.Sound('./sounds/score.wav'),
// Music
BackgroundMusic: new ex.Sound('./sounds/two_left_socks.ogg')
} as const;
typescript
// resources.ts
export const Resources = {
// Relative to /public in vite
...
// Sounds
FlapSound: new ex.Sound('./sounds/flap.wav'),
FailSound: new ex.Sound('./sounds/fail.wav'),
ScoreSound: new ex.Sound('./sounds/score.wav'),
// Music
BackgroundMusic: new ex.Sound('./sounds/two_left_socks.ogg')
} as const;
Listen to the flap.wav:
Download audio
Listen to the fail.wav:
Download audio
Listen to the score.wav:
Download audio
Listen to the background music: