Just about every modern game lets the player customize the input according to their own preferences. This recipe will rely on jMonkeyEngine to do the work for us, and we will use Nifty GUI as a visual aid. We'll use RawInputListener
to work out which keys have been pressed and divide them between key codes and characters using the Keyboard
class.
The recipe will depend on there being some bindings in InputManager
. If you already have a game, this would not be a problem. If not, it will describe how to add a couple of bindings for the example to work.
Following the pattern from previous recipes, we'll start defining the controls, then move on to the screen, and finally work on the controller. Adding the controls and screen will consist of the following eight steps:
Inside a
<nifty-control>
tag, we define a new<controlDefinition name="keyBindingControl">
.Here, we'll add a horizontal spanning panel with some margin...