toto88x Posted April 7, 2016 Share Posted April 7, 2016 Hi, I know about the preload, create and update function in Phaser. But I only really recently learned about the init function. And now I'm wondering: when am I supposed to use it? What code should I put in the init function? Setting the physics engine? Scaling the game? Adding a background color? Something else? So far I put all of this at the beginning of the create function. Is that a bad idea? will using the init function instead have any advantage? Thanks! Link to comment Share on other sites More sharing options...
drhayes Posted April 7, 2016 Share Posted April 7, 2016 ¯\_(ツ)_/¯ The init function receives any parameters that you add to the end of the "game.state.start" call. AFAIK, that's the only way to pass info from one state to another without using variables outside of the state. Tom Atom 1 Link to comment Share on other sites More sharing options...
toto88x Posted April 8, 2016 Author Share Posted April 8, 2016 So there are no best practices on this? Link to comment Share on other sites More sharing options...
drhayes Posted April 11, 2016 Share Posted April 11, 2016 I wouldn't worry about "best practices" right now? If you haven't found a situation where one state needs to pass information to another state that's not via global variables... then sounds like you don't really need an init function. Or maybe you put it in and everything's still fine. Nothing's a bad idea if your game works. Shipping is a feature ahead of best practices. mattstyles 1 Link to comment Share on other sites More sharing options...
Recommended Posts