Jump to content

A problem about state.start,Who can help me?


yiyu
 Share

Recommended Posts

I get a error when I use game.state.start() function in phaser.min.js 2.4.6.

I want back to previous state(in my code ,it is "Main" state) with a button tap function in "Play" state.so I use the code:game.state.start("Main").but there throw a error:Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D'.

It seems like that the preload function in "Main" state been called again,because the game run well when I replace the code to : game.state.start("Main",true,true).In fact ,I must keep the game.Cache in game ,so the gamer woudn't wait for a long time.

Who can help me?Thanks to any replies!

Link to comment
Share on other sites

I don't really understand your problem.

It sounds like your 'Main' state has its own preload function. You would be best off loading all your assets in a state called Preload, then only going to 'Main' when everything is loaded. That way your assets will still be ready to use if you have to switch between states so you won't need to load anything again.

Link to comment
Share on other sites

18 hours ago, Arcanorum said:

I don't really understand your problem.

It sounds like your 'Main' state has its own preload function. You would be best off loading all your assets in a state called Preload, then only going to 'Main' when everything is loaded. That way your assets will still be ready to use if you have to switch between states so you won't need to load anything again.

Thank you very much!Your answer is perfect to solve my problem.I just add a 'Preloader' state to load all game assets before starting 'Main' and 'Play' function.And now my game is running well. Thanks again:)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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