I'm making a little game that draws "Game over" at a certain event and I want the player to lose control of the character when this happens. I am using key adapter in a different class and adding it in the constructor, like this:
addKeyListener(new GetKeyStroke(this));
My game over code looks like this (it's in the paint method):
if (gameOver) {
g.setFont(pauseFont);
g.setColor(Color.WHITE);
g.drawString("Game Over!", screenSize.width / 2 - 110, screenSize.height / 5);
}
I've tried using
removeKeyListener(new GetKeyStroke(this));
but from what I know, that creates a new object and that's why it doesn't work.
Any help is greatly appreciated