v0.8.0: added basic key action and key mapping support

This commit is contained in:
Evan Debenham
2019-10-28 21:06:02 -04:00
parent 4f430015c3
commit df3a0a010b
8 changed files with 136 additions and 35 deletions

View File

@@ -21,12 +21,19 @@
package com.watabou.input;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.watabou.noosa.Game;
import com.watabou.utils.PointF;
public class InputHandler extends InputAdapter {
public InputHandler( Input input ){
input.setInputProcessor( this );
input.setCatchKey( Input.Keys.BACK, true);
input.setCatchKey( Input.Keys.MENU, true);
}
public void processAllEvents(){
PointerEvent.processPointerEvents();
KeyEvent.processKeyEvents();
@@ -79,16 +86,22 @@ public class InputHandler extends InputAdapter {
@Override
public synchronized boolean keyDown( int keyCode ) {
//TODO should check if key is mapped and ignore if it isn't?
KeyEvent.addKeyEvent( new KeyEvent(keyCode, true) );
return true;
if (KeyBindings.isBound( keyCode )) {
KeyEvent.addKeyEvent( new KeyEvent( keyCode, true ) );
return true;
} else {
return false;
}
}
@Override
public synchronized boolean keyUp( int keyCode ) {
//TODO should check if key is mapped and ignore if it isn't?
KeyEvent.addKeyEvent( new KeyEvent(keyCode, false) );
return true;
if (KeyBindings.isBound( keyCode )) {
KeyEvent.addKeyEvent( new KeyEvent( keyCode, false ) );
return true;
} else {
return false;
}
}
// ********************