Difference between revisions of "Input Handling"
Line 6: | Line 6: | ||
* [[Polling the Current Input State]] | * [[Polling the Current Input State]] | ||
* [[Event-Driven Input]] | * [[Event-Driven Input]] | ||
+ | |||
+ | [[Category:Input]] |
Revision as of 17:06, 8 August 2013
Slick input can handle keyboard, mouse and controller input (mostly just wrapped carefully around the existing LWJGL functionality). The input processing is handled by the Input class. To receive input you need to get an instance of this class and call poll()
during the game loop to check input and fire events to registered listeners. If you're using the GameContainer framework then this is all handled for you and you can simply call GameContainer.getInput() (which is the preferred option).
Input can be retrieved in two ways (discussed in later section). You can either poll the keyboard, mouse and controllers by using the direct method calls on Input such as isKeyPressed()
. This will give you the state of the input at any time. Alternatively you can register a listener with the Input instance you're using with addListener and then implement the InputListener interface to handle notifications of input changes. Note that if you're using an extension of BasicGame then this is done for you and you can simply override the input event handler methods.