babev Posted March 28, 2014 Share Posted March 28, 2014 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 More sharing options...
rich Posted March 29, 2014 Share Posted March 29, 2014 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 More sharing options...
BunBunBun Posted March 29, 2014 Share Posted March 29, 2014 rich, what format you recommend to use for audio? what do you think about m4a? Link to comment Share on other sites More sharing options...
Zenryo Posted March 29, 2014 Share Posted March 29, 2014 On examples it says that ogg is the recommended format since most browsers can play it. Link to comment Share on other sites More sharing options...
BunBunBun Posted March 29, 2014 Share Posted March 29, 2014 but if make a game for mobile? iOS don't support ogg. Link to comment Share on other sites More sharing options...
Recommended Posts