Jump to content

Spacebar tap function?


xronn
 Share

Recommended Posts

I'm using the spacebar as shown below -

interactButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);

Then I call it as such - 

if (quest1 == false && interactButton.isDown)

The problem is if you tap the spacebar you hold it down for 3 or 4 milliseconds thus meaning the if statement is run 3 or 4 times, which isn't any good.

If I change it too - 

if (quest1 == false && interactButton.isUp)

Then when I tap the spacebar the whole time it's up after the tap which is until I press it down again it loops through the if statement which isn't any good either. Does Phaser support something like a tap listener so when its down and then up it runs once not 100s of times as it currently does.

Link to comment
Share on other sites

 

This is basically what I need however it uses the isDown call which is what Im using... Do you know if it solves the issue just by adding time between events, I didn't really want to start adding timed delays between keyboard input.

 

A callback method will work for everyone who uses a key for a single purpose e.g. moving the player up... However my spacebar input is used as an interaction thus requiring it to be used all over my game so it can't have a single callback. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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