Global key event in all states

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?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.