stevefromio Posted July 27, 2015 Share Posted July 27, 2015 Say I have a intro state, play state, and game over state. What if I want to pre-load everything in the intro state, but have access to them in the play and game over state? Link to comment Share on other sites More sharing options...
rich Posted July 27, 2015 Share Posted July 27, 2015 The Cache isn't state specific - once you populate it, the items remain in there unless you specifically remove them. Link to comment Share on other sites More sharing options...
stevefromio Posted July 27, 2015 Author Share Posted July 27, 2015 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 More sharing options...
rich Posted July 27, 2015 Share Posted July 27, 2015 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 More sharing options...
stevefromio Posted July 27, 2015 Author Share Posted July 27, 2015 Got it. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts