Jump to content

Global key event in all states


Zampano
 Share

Recommended Posts

Hey there,

I'm trying to get a key to always call a certain function, regardless of which state my game is in. At the moment, my code is this:
 

var escKey = null 

BasicGame.Boot = function (game) {
   //...
};

BasicGame.Boot.prototype = {

init: function () {    	
   escKey = game.input.keyboard.addKey(Phaser.Keyboard.ESC);
   escKey.onDown.add(function(){console.log("esc")}, game);
}

And so on. escKey stays defined in all states, but onDown doesn't trigger. If I move the two lines within init to a state, I can use ESC in that state, but not in any state after that.

Is there a way to do this?

Link to comment
Share on other sites

  • 1 month later...
 Share

  • Recently Browsing   0 members

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