GameDemon Posted December 21, 2015 Share Posted December 21, 2015 Is it possible to persist keyboard events between states? I am setting one with `game.input.keyboard.addKey()` and `myKey.onUp.add()` in the first state `create` function, but changing states seems to remove the listener. I'm using 2.4.4, but can't find the documentation for what occurs between state transitions, is this available somewhere? Thanks in advance Link to comment Share on other sites More sharing options...
drhayes Posted December 21, 2015 Share Posted December 21, 2015 AFAIK it's not possible, no. I just end up re-binding them on state transition. Link to comment Share on other sites More sharing options...
GameDemon Posted December 21, 2015 Author Share Posted December 21, 2015 Thanks Dr! I was looking at that file but managed to miss that line Hm… can I ask if there is a good pattern or best-practice for storing logic/methods outside of the various game states, so that it doesn't have to be redeclared? Are people extending Game? Link to comment Share on other sites More sharing options...
drhayes Posted December 22, 2015 Share Posted December 22, 2015 I'd love to hear other people chime in but here's what I do (not authoritative! not a best practice or anything! just what works for me!) If it's something that needs to be a part of the update or render cycle I make a Phaser.Plugin. Anything that manages tweens, or ensures timings between events, even particle effects, that kind of thing... I tend to make those Plugins. Most of those plugins make themselves properties of the game instance. If it's just a collection of stuff that would be handy to reference elsewhere I make an object and stick it on the game instance, too. For example, every layer in my game is hung off a "groups" property on the game instance. Link to comment Share on other sites More sharing options...
GameDemon Posted December 24, 2015 Author Share Posted December 24, 2015 Thanks a lot for your detailed answer Dr, I should probably make it a separate thread because it's an interesting topic and people might not find your post here. Link to comment Share on other sites More sharing options...
Recommended Posts