I have a tetris clone game that is all complete, but I put some graphic buttons on it for controlling the pieces by clicking them.
The pieces move perfect when I use the keyboard events, like keypress = left, move piece left.
They also move perfect when I put the code to move the piece inside the mouse event, like mousepressed = check which graphic button is clicked, move piece.
The problem with putting the movement code inside mousepressed is that if the user keeps the mouse button down, the mouse event doesn’t detect this. In order to handle this I have to create a flag so when user clicks the left arrow, moveLeft = true, then check for the flags in the run method and move the piece accordingly. Doing it this way causes lag in movement or will move too much, even if the user just clicks the arrow once, the piece will move 2 spots sometimes.
This seems to be a problem by checking the mouse movement flags in the run method. This causes lag or speed jumps. Where if the movement code is in the mouse event, it fires with the event.
if MousePressed acted like KeyPressed and kept firing as long as the mouse button is down, everything would work fine.
Just spent all day trying to figure this out.