yiyu Posted April 9, 2016 Share Posted April 9, 2016 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 More sharing options...
Arcanorum Posted April 10, 2016 Share Posted April 10, 2016 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 More sharing options...
yiyu Posted April 11, 2016 Author Share Posted April 11, 2016 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 More sharing options...
Recommended Posts