Jump to content

Persist keyboard events between states


GameDemon
 Share

Recommended Posts

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

Thanks Dr! I was looking at that file but managed to miss that line  :rolleyes:

 

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...