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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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