jerome Posted February 8, 2014 Share Posted February 8, 2014 I'd like to code a short example about using states for examples.phaser.io which would be illustrating the basic template Making some tests, I noticed the sprite I wanted textured with an asset wasn't displayed if I started a new state within the preloader function of the current state. I checked : the relevant cache entry exists yet and the image is well downloaded in both cases. Do you confirm to never start a state from within the preloader function ? code : window.onload = go;var myGame;var gameState = {};gameState.one = function(game){};gameState.two = function(game){};gameState.one.prototype = { preload: function(){ this.load.image('raph', '/game2/images/raph.png'); //this.game.state.start('display'); // <= if you start next state here (and not in create), the sprite isn't displayed }, create: function(){ this.game.state.start('display'); }};gameState.two.prototype = { create: function(){ this.add.sprite(100,100,'raph'); }};function go() { myGame = new Phaser.Game(800,600, Phaser.AUTO); myGame.state.add('boot', gameState.one); myGame.state.add('display', gameState.two); myGame.state.start('boot');} Link to comment Share on other sites More sharing options...
rich Posted February 8, 2014 Share Posted February 8, 2014 The problem is the image hasn't loaded. The preload function is called fully, so it adds an image to the loader and then gets told to swap states immediately. State swap should either go in create function, or in onLoadComplete callback. jerome 1 Link to comment Share on other sites More sharing options...
jerome Posted February 8, 2014 Author Share Posted February 8, 2014 ok,I guess it was something like that ... the image is well downloaded by the browser but the state has already changed Link to comment Share on other sites More sharing options...
Recommended Posts