Jump to content

Key Hold CallBack


pandavigoureux29
 Share

Recommended Posts

Hi all,

 

I searched a long time for a callback that would be called each update when a key is pressed, like a key.onHold.add(this.onHold, this);

 

I wasn't able to find anything close in the doc or the forum, so I decided to do my own manager, and share it here.

 

Bascically the usage is like that :

 

this.keyManager = new InputKeyEventsManager(game,this);

 

That creates an Instance of InputKeyEventsManager. It "inherits" from Phaser.Sprite so the update is automatically called from the game.

The parameters are :

- the current game reference

- the targeted object, on which the callback will be called

 

Then to monitor a key:

 

this.key = this.keyManager.createKey(<Phaser.Keyboard.KeyCode>,<onDown>,<onHold>,<onUp>); 

 

That's it.

 

Now that this is done, here's my question :

Why would not this be implemented ? 

 

Don't misunderstand me, I'm sure there's a good reason and I'm just trying to understand it.

 

It's just ... I was sure this would be implemented when I first saw the Key.onDown and Key.onUp function. So I was very disappointed not seeing an onHold one.

Maybe what I'm doing is drastically cutting the performances? 

Please let me know. 

 

Thanks

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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