When anything is typed in, the letter shows up twice, instead of just once. Obviously, the loop instead of just adding the second character typed to the string is storing the info and adding the entire text back to itself, instead of just concatenating the new character.
create() { var enteredText = ''; this.input.keyboard.on('keydown', function (event) { enteredText += event.key;
console.log(enteredText);
}
The same problem happens with the example given (link above): Why, and how to just get the newly entered key to concatenate once to the original string?
Thanks but that doesnât solve my problem. Why would mine be sending extra events? As I said itâs the same as the example online which also gives me the same errorâdouble keys.
Adding console.log(event.type, event.key); gives me a single response âkeydown, aâ.
It runs the entire loop twice, but why would it do that? âCreateâ is not a loop.
This is my entire code:
class GameScene extends Phaser.Scene{
The reason itâs sending more than just once is a browser thing (afaik). best solution is checking on keyup, another solution is making a variable thatâs true/false, having it set to false when ondown is triggered and making a tween that sets it to true after some time and making an IF statement that does that it only triggers when itâs false/true
Tried in Chrome and Firefoxâsame result.
Tried keyup, same problem.
Am I really the only one having this problem?
I canât see a problem with my code at all.
When I press any key, the entire callback function runs twice. Why?