ENGINE GUIDE

Use ImgSearch game sounds in Phaser

Load ImgSearch game sound packs in Phaser with this.load.audio, giving an OGG file and a WAV fallback, and play them with this.sound. Phaser is a 2D framework, so the 3D model kits are not for it.

Phaser is a 2D framework, so our 3D model kits aren’t made for it; they target 3D engines such as Three.js, Godot and Unity. The game sound packs work in Phaser as they are.

What’s in a sound pack

Each pack downloads as one ZIP with a wav/ folder of 44.1 kHz stereo masters and an ogg/ folder of Ogg Vorbis copies, numbered in pack order. Copy the sounds you need into your game’s assets folder; the paths below are examples.

Load and play sounds

Give this.load.audio the OGG first and the WAV as a fallback. Phaser loads the first format the browser can play: OGG files are much smaller, and some Safari versions can’t play them, so the WAV covers those.

level.js
class Level extends Phaser.Scene {
  preload() {
    // Phaser loads the first format the browser can play.
    this.load.audio('coin', ['sounds/coin.ogg', 'sounds/coin.wav']);
    this.load.audio('jump', ['sounds/jump.ogg', 'sounds/jump.wav']);
  }

  create() {
    this.input.keyboard.on('keydown-SPACE', () => this.sound.play('jump'));
    this.input.on('pointerdown', () => this.sound.play('coin', { volume: 0.8 }));
  }
}

new Phaser.Game({ type: Phaser.AUTO, width: 800, height: 600, scene: Level });

Looping sounds and the audio lock

Browsers keep audio locked until the player clicks, taps or presses a key. Phaser unlocks it on the first input, so start a loop when the sound manager reports it is unlocked:

Looping sound
// preload(): this.load.audio('engine-hum', ['sounds/engine-hum.ogg', 'sounds/engine-hum.wav']);
// create(): audio stays locked until the first click, tap or key press.
const hum = this.sound.add('engine-hum', { loop: true, volume: 0.4 });
if (this.sound.locked) {
  this.sound.once(Phaser.Sound.Events.UNLOCKED, () => hum.play());
} else {
  hum.play();
}

We checked these snippets with Phaser 3.90 and Phaser 4.2.

All game assets