Game Development Reference
In-Depth Information
addInputMappings();
}
7. Once
InputManager
detects any of the actions and sends them our way, we
will just forward them to the
GameCharacterControl
object by applying the
sensitivity value to the analog input as follows:
public void onAnalog(String name, float value, float
tpf) {
if(character != null){
character.onAnalog(name, value * sensitivity,
tpf);
}
}
public void onAction(String name, boolean isPressed,
float tpf) {
if(character != null){
character.onAction(name, isPressed, tpf);
}
}
8. We're actually almost done with this recipe. We just need to make sure that we re-
set everything when
AppState
is not to be used anymore. We do this by over-
riding the cleanup method. Here, we remove all the mappings and remove this in-
stance from listeners of
inputManager
as follows:
public void cleanup() {
super.cleanup();
for (InputMapping i : InputMapping.values()) {
if (inputManager.hasMapping(i.name())) {
inputManager.deleteMapping(i.name());
}
}
inputManager.removeListener(this);
}