Jump to content

Pass pre-loaded sounds from one game state to another?


stevefromio
 Share

Recommended Posts

I get a Phaser.Loader fileComplete invalid index 0.

 

var introScene = new Phaser.State();
 
introScene.prototype = {
preload: function() {
console.log("preload function()")
},
create: function() {
console.log("create function()");
game.add.sprite(0, 0, 'star');
},
update: function() {
console.log("update function()");
}
}
 
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
game.state.add('intro',introScene);
//game.state.start('intro');
var score = 0;
var scoreText;
 
function preload() {
 
game.load.image('sky', 'assets/sky.png');
game.load.image('ground', 'assets/platform.png');
game.load.image('star', 'assets/star.png');
game.load.spritesheet('dude','assets/dude.png', 32, 48);
game.load.spritesheet('enemy','assets/baddie.png', 32, 32);
game.load.audio('music', 'assets/soundtrack.mp3');
game.load.audio('enemy-move','assets/cyborg-move.wav');
game.load.audio('enemy-jump','assets/cyborg-jump.wav');
game.state.start('intro');
}
Link to comment
Share on other sites

You are changing the state in the preload function - before the assets have even had a chance to load. Just calling 'game.load.image' (etc) does not load them at that point, it just adds them to the load queue. Change state in the create function, at least, and check the docs (because they explain all of this too)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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