Jump to content

never start a state within preloader ?


jerome
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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