Skip to content

Instantly share code, notes, and snippets.

@corpsefilth
Created February 21, 2015 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corpsefilth/6a06e7c1346877caa102 to your computer and use it in GitHub Desktop.
Save corpsefilth/6a06e7c1346877caa102 to your computer and use it in GitHub Desktop.
Loading music assets. Phaser
// Load the music in 2 different formats, in the preload function
game.load.audio('music', ['assets/music.ogg', 'assets/music.mp3']);
// Add and start the music in the 'create' function
// Because we want to play the music when the play state starts
this.music = game.add.audio('music'); // Add the music
this.music.loop = true; // Make it loop
this.music.play(); // Start the music
// And don't forget to stop the music in the 'playerDie' function
// Otherwise the music would keep playing
this.music.stop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment