Created
June 11, 2012 00:54
-
-
Save homelinen/2907928 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Oxyfps; | |
import com.jme3.input.InputManager; | |
import com.jme3.input.KeyInput; | |
import com.jme3.input.MouseInput; | |
import com.jme3.input.controls.ActionListener; | |
import com.jme3.input.controls.KeyTrigger; | |
import com.jme3.input.controls.MouseButtonTrigger; | |
public class InputController implements ActionListener { | |
private InputManager inputManager; | |
private boolean keyup[]; | |
private boolean keydown[]; | |
private boolean mousedown[]; | |
private boolean mouseup[]; | |
public InputController(InputManager inputManager) { | |
keyup = new boolean[255]; | |
keydown = new boolean[255]; | |
mouseup = new boolean[5]; | |
mousedown = new boolean[5]; | |
this.inputManager = inputManager; | |
setUpKeys(); | |
} | |
private void setUpKeys() { | |
//Mouse | |
inputManager.addMapping("" + MouseInput.BUTTON_LEFT, new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); | |
inputManager.addListener(this, "" + MouseInput.BUTTON_LEFT); | |
//Keyboard | |
inputManager.addMapping("" + KeyInput.KEY_A, new KeyTrigger(KeyInput.KEY_A)); | |
inputManager.addMapping("" + KeyInput.KEY_D, new KeyTrigger(KeyInput.KEY_D)); | |
inputManager.addMapping("" + KeyInput.KEY_W, new KeyTrigger(KeyInput.KEY_W)); | |
inputManager.addMapping("" + KeyInput.KEY_S, new KeyTrigger(KeyInput.KEY_S)); | |
inputManager.addListener(this, "" + KeyInput.KEY_A); | |
inputManager.addListener(this, "" + KeyInput.KEY_D); | |
inputManager.addListener(this, "" + KeyInput.KEY_W); | |
inputManager.addListener(this, "" + KeyInput.KEY_S); | |
//Debug | |
inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T)); | |
inputManager.addListener(this, "wireframe"); | |
} | |
/** | |
* Value is an isPressed method | |
*/ | |
@Override | |
public void onAction(String binding, boolean value, float tpf) { | |
if (value) { | |
keyup[Integer.parseInt(binding)] = true; | |
keydown[Integer.parseInt(binding)] = false; | |
} else { | |
keyup[Integer.parseInt(binding)] = false; | |
keydown[Integer.parseInt(binding)] = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment