gianthead Posted June 25, 2015 Share Posted June 25, 2015 TLDR: What do people recommend for implementing FSMs in Phaser? Details: Since FSMs make it a lot easier to manage the complexity of game states, I try to use them in all my games. This is not the same as what Phaser calls states. That looks like it's more for screen management. This article explains the state pattern that I'm referring to pretty clearly. So I'm wondering how do people recommend implementing FSMs within a Phaser state? What patterns or plugins they use? Or do they roll their own? If roll your own, any advice on implementation? Or maybe my understanding of Phaser states is mistaken and they can be used for FSMs and I just don't know how? Link to comment Share on other sites More sharing options...
Secretmapper Posted June 25, 2015 Share Posted June 25, 2015 I use https://github.com/eonarheim/TypeState Link to comment Share on other sites More sharing options...
george Posted June 25, 2015 Share Posted June 25, 2015 Hi,I used both of those two:https://github.com/jakesgordon/javascript-state-machinehttps://github.com/ifandelse/machina.js Jakesgordon's StateMachine was very useful in a pinball machine to manage the state of every moving part and also the overall state of the pinball machine. I never missed a hierarchical fsm but that's what machina is supporting now.Machina seems to be the more engeneered fsm- that's why I forced me to try it in my last project: to manage the state of a popping champagne bottle. Yeah that's right, I could have done it with a bunch of state variables in this case but it was for the sake of fun Not to mention that it was a full success. So I have still the dilemma that I have to choose one of them for my next project. There is really no need to brew your own fsm. RegardsGeorge drhayes and SET001 2 Link to comment Share on other sites More sharing options...
BdR Posted June 25, 2015 Share Posted June 25, 2015 I don't use several Phaser.States during gameplay, I only use a Phaser.State for each screen, and the gameplay just counts as one screen. So there's one State for the main menu, one for the level select screen and one for the actual game. See Phaser.State examples in the forum here or here. During the gameplay State I just use a variable to distinguish the gameplay situations. Very simple maybe, but for me it does the job. So something like this:var GAME_INTRO = 0; // short animation and show "Level 1"var GAME_PLAYING = 1;var GAME_GAMEOVER = 2;// at start of gamethis._mystate = GAME_PLAYING;And for example, when handling the player input first check if it's not during intro or game over// don't handle input in intro or gameoverif (this._mystate == GAME_PLAYING) { // handle player input}In short, I guess my games aren't complex enough (yet) to require a Finite-state Machine. Link to comment Share on other sites More sharing options...
gmalone Posted July 10, 2015 Share Posted July 10, 2015 Thanks for raising this topic. I had not been formally knowledgeable about FSMs, though had used similar methods in some cases. The article you linked to is an excellent explanation of the concept and its variations. Seems to me the concept of FSM is portable to Javascript, and by extension, to Phaser apps. Phaser states, as I currently understand and use them, are wired to assumptions built into Phaser about expected create-update-render domains within each state. But I can see how one would implement FSMs in JavaScript with the switch-case statement central to the flow. Richard Davey (author of Phaser) would be an excellent person to comment on this. Link to comment Share on other sites More sharing options...
Recommended Posts