pheaset Posted October 27, 2016 Share Posted October 27, 2016 Hey 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 Pheaset 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('paddle','paddle.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() { game.physics.startSystem(Phaser.Physics.ARCADE); startButton = game.add.button(game.world.width*0.5, game.world.height*0.5, 'button', startGame, this, 1, 0, 2); startButton.anchor.set(0.5); music = game.add.audio('Good-Riddance') this.music = this.add.audio("Good-Riddance") this.game.sound.setDecodedCallback(["Good-Riddance"]); if(playing === true) { music.play() }else{ music.mute = false; } Quote Link to comment Share on other sites More sharing options...
Xesenix Posted February 20, 2017 Share Posted February 20, 2017 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 1,//volume true//loop ); 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.