DanielDunderfelt Posted April 26, 2015 Share Posted April 26, 2015 Hello Phaserists! I just started out with Phaser, and was wondering if there's a built-in way to have a global state object. What I mean is an object whose preload, update, create and render methods are always called, regardless of which other state the game is currently in. I've solved it by having a singleton object with the needed methods, which I always import into my state files (I use ES6). Then I can call its methods from the respective methods of the real state. While this solution isn't bad, it would be useful to have a built-in way to declare a global state object, maybe something like game.setGlobalState(myStateObject)// ornew Phaser.Game(..., myStateObject)Something to consider? Link to comment Share on other sites More sharing options...
rich Posted April 26, 2015 Share Posted April 26, 2015 There's no concept of a "global" State in Phaser (it's not something I've ever come across in other game frameworks either to be honest). Could you not just create a 'base' state from which all other states extend? So long as the extended states didn't override the core methods, they would be called every time. I don't really understand what kind of game structure would ever need this! but it's how I'd go about it for sure. Link to comment Share on other sites More sharing options...
Recommended Posts