xronn Posted December 3, 2015 Share Posted December 3, 2015 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 More sharing options...
CtlAltDel Posted December 3, 2015 Share Posted December 3, 2015 read: http://phaser.io/examples/v2/input/keyboard-justpressedfor a lot of options Link to comment Share on other sites More sharing options...
Skeptron Posted December 3, 2015 Share Posted December 3, 2015 http://www.html5gamedevs.com/topic/3541-listener-functions-how-do-i-properly-use-them/ Link to comment Share on other sites More sharing options...
xronn Posted December 3, 2015 Author Share Posted December 3, 2015 read: http://phaser.io/examples/v2/input/keyboard-justpressedfor a lot of options 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. http://www.html5gamedevs.com/topic/3541-listener-functions-how-do-i-properly-use-them/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 More sharing options...
drhayes Posted December 3, 2015 Share Posted December 3, 2015 Why not have multiple callbacks? onDown is a Phaser.Signal, which means it can have multiple listeners. Each callback could decide if it's appropriate to respond to the spacebar being pressed dynamically. Link to comment Share on other sites More sharing options...
Recommended Posts