Jump to content

Game starting before assets load?


babev
 Share

Recommended Posts

First time working with phaser, I'm having some trouble implementing music into my game. I'm using two states, a load state(just preloading) and a main state (which is where the game begins).

var load_state = {	preload: function() {        // Function called first to load all the assets		game.stage.backgroundColor = '#71c5cf';		game.load.image('background', 'assets/title.png');				//load head                game.load.image('head', 'assets/head.png');   //normal				//load wall                game.load.image('wall', 'assets/wall.png');  				//load sound                game.load.audio('jump', 'assets/jump.wav');		game.load.audio('death', 'assets/dead.wav');		game.load.audio('music', 'assets/music.mp3');    },		create: function() {		// When all assets are loaded, go to the 'main' state (game)		music = game.add.audio('music');		music.play();                game.state.start('main');	}}

All the image assets load fine and are present when the game switches to the 'main' state. However, the music doesn't start playing until 20-30 seconds after the states change. I want it to start playing as soon as the states change.

Link to comment
Share on other sites

You're using an mp3, so the delay is the time the mp3 is taking to decode. You can either use another format (which I'd recommend), or if you look in the resources folder you'll find a Project Templates folder. Inside there have a look at the templates, you'll see in our Preloader.js files we have a condition to check if the music has finished decoding before carrying on with the game. So you could copy that.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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