JSLegendDev / 2d-portfolio-kaboom

Web dev portfolio as a 2D game
https://jslegenddev.github.io/portfolio/
MIT License
156 stars 60 forks source link

Arrow key movement bug #4

Open tjl9tq opened 1 month ago

tjl9tq commented 1 month ago

There's a bug around character movement with arrow keys. The current onkeydown function will run the movement code for any key pressed as long as one of the arrow keys is pressed. This results in the movement code running per key pressed, effectively multiplying the characters movement speed by the number of keys pressed.

You can see this is a the live demo. If you click an arrow key + any other key, movement speed doubles and increases for each key pressed.

Suggested fix: adding a guard to prevent movement code from running if the key pressed is not a direction like this: if (!directions.includes(key)) return

JSLegendDev commented 1 month ago

Thanks for reporting this!