Hello folks,
Me and my parnter are making a Tetris game for a project and have encountered a problem concerning the KeyListener class and we're aren't quite sure how to get around it. I won't post ALL the code but here's the essential:
The problem we a have is for the "Speed up" control. We want the currently controlled Tetrimino (a "building-block" so to speak) to speed up
immediately when the key is pressed, as well as to slow down as soon as the user releases of the key (so is the purpose of the interrupt() in the speed control functions of Gravity).
When I press down on the Down key (default controls) the tetrimino speeds up immediately but after a while stops moving completely. It only starts to move after if I release the Down key or do something else with it (such as rotate or move it). I'd assume that this is because after holding the key for a while the OS "spams" that key so speak (in other words, it repetitively invokes a "pressed" command for that key), which would evidently cause the Gravity
thread to be interrupted non-stop, thus not allowing it to let a piece fall.
I can fix this problem by remove the "interrupt()" calls but this causes the speed up command to be delayed, which is even more annoying. Any ideas on how to go about this problem?
Thank-you.