Jump to content


Recommended Posts


I am currently polishing off my Breakout or Brick-Breaker game (whichever you prefer to call it). I am trying to add music to the game when the start button is pressed and then sound effects every time a brick is destroyed.

Unfortunately Phaser keeps saying Key "Sample" is not found in cache.

I have tried using Phasers examples and basing the music off that but to no avail.

I am new to programming with Phaser and would really appreciate the help. When the game is finished i will post a link.

Thanks in Advance


here is my code

var game = new Phaser.Game(480, 320, Phaser.AUTO, null, {
    preload: preload, create: create, update: update
var firework;;

var music = Phaser.Sound;

var lives = 1;
var livesText;
var lifeLostText;
var ball;
var paddle;
var bricks;
var newBrick;
var brickInfo;
var scoreText;
var score = 0;
var playing = false;
var startButton;
function preload() {
    game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
    game.scale.pageAlignHorizontally = true;
    game.scale.pageAlignVertically = true;
    game.stage.backgroundColor = '#eee';
    game.load.image('ball',  'ball.png');
    game.load.image('brick', 'img/brick.png')
    game.load.spritesheet('ball', 'img/wobble.png', 20, 20);
    game.load.spritesheet('button','button.png', 120, 40);
    game.load.audio('Good-Riddance', 'Good-Riddance.mp3');
function create() {
      startButton = game.add.button(game.world.width*0.5, game.world.height*0.5, 'button', startGame, this, 1, 0, 2);

      music = game.add.audio('Good-Riddance')
      this.music = this.add.audio("Good-Riddance")
      if(playing === true)
        music.mute = false;


Link to comment
Share on other sites

  • 3 months later...

I start my music samples like this:

// that bit is important for RAM consumption you usualy dont need WebAudio if you dont do fancy things
window.PhaserGlobal = {
  disableWebAudio: true
var game = new Phaser.Game(480, 320, Phaser.AUTO, null, {
  preload: function() { 
    game.load.audio('Good-Riddance', 'Good-Riddance.mp3');
  create: function() {
    var soundtrack = game.sound.play(
      'Good-Riddance',//cache key
    soundtrack.mute = false;// if you want to mute it

If something doesnt work check browser console for errors F12 maybe your file is in different place?

Or you running script from file path instead of server can be problem sometimes but should be in this case but if it is you can use for example brackets editor that starts small development server for serving your files.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...