Reputation: 5024
Slick's Input
class has a isKeyPressed()
method that returns a boolean value according to whether the specified key has been pressed. I'd like to implement a way to check if a key has been released in the same fashion.
I looked into adding a KeyListener
to the input object, and overriding the keyReleased()
method. However, the way I am currently handling input is in the update()
method of my BasicGame
. By implementing the aforementioned solution, I fracture my code and handle input in two different places which I'd like to avoid.
Upvotes: 0
Views: 1047
Reputation: 578
Input doesn't have a keyReleased method because it is a polling type of class. It only holds a boolean value if the key had been pressed, and then relinquishes that value upon request of seeing if it was pressed by input.isKeyPressed(VK_KEY).
If you look at the InputTest example provided in the slick trunk by Kevin Glass, you will see that BasicGame, and BasicGameState both carry a method called isKeyPressed/isKeyReleased.
InputTest.java Slick2D resource
These are the methods you are looking for, as they will provide you with more control over what happens when keys are pressed or released.
Upvotes: 1