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);'Good-Riddance', 'Good-Riddance.mp3');
function create() {
      startButton = game.add.button(*0.5,*0.5, 'button', startGame, this, 1, 0, 2);

      music ='Good-Riddance') ="Good-Riddance")["Good-Riddance"]);
      if(playing === true)
        music.mute = false;


Share this post

Link to post
Share on other sites

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() {'Good-Riddance', 'Good-Riddance.mp3');
  create: function() {
    var soundtrack =
      '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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.