Search in sources :

Example 6 with InputProcessor

use of com.badlogic.gdx.InputProcessor in project libgdx by libgdx.

the class AndroidInput method processEvents.

void processEvents() {
    synchronized (this) {
        justTouched = false;
        if (keyJustPressed) {
            keyJustPressed = false;
            for (int i = 0; i < justPressedKeys.length; i++) {
                justPressedKeys[i] = false;
            }
        }
        if (processor != null) {
            final InputProcessor processor = this.processor;
            int len = keyEvents.size();
            for (int i = 0; i < len; i++) {
                KeyEvent e = keyEvents.get(i);
                currentEventTimeStamp = e.timeStamp;
                switch(e.type) {
                    case KeyEvent.KEY_DOWN:
                        processor.keyDown(e.keyCode);
                        keyJustPressed = true;
                        justPressedKeys[e.keyCode] = true;
                        break;
                    case KeyEvent.KEY_UP:
                        processor.keyUp(e.keyCode);
                        break;
                    case KeyEvent.KEY_TYPED:
                        processor.keyTyped(e.keyChar);
                }
                usedKeyEvents.free(e);
            }
            len = touchEvents.size();
            for (int i = 0; i < len; i++) {
                TouchEvent e = touchEvents.get(i);
                currentEventTimeStamp = e.timeStamp;
                switch(e.type) {
                    case TouchEvent.TOUCH_DOWN:
                        processor.touchDown(e.x, e.y, e.pointer, e.button);
                        justTouched = true;
                        break;
                    case TouchEvent.TOUCH_UP:
                        processor.touchUp(e.x, e.y, e.pointer, e.button);
                        break;
                    case TouchEvent.TOUCH_DRAGGED:
                        processor.touchDragged(e.x, e.y, e.pointer);
                        break;
                    case TouchEvent.TOUCH_MOVED:
                        processor.mouseMoved(e.x, e.y);
                        break;
                    case TouchEvent.TOUCH_SCROLLED:
                        processor.scrolled(e.scrollAmount);
                }
                usedTouchEvents.free(e);
            }
        } else {
            int len = touchEvents.size();
            for (int i = 0; i < len; i++) {
                TouchEvent e = touchEvents.get(i);
                if (e.type == TouchEvent.TOUCH_DOWN)
                    justTouched = true;
                usedTouchEvents.free(e);
            }
            len = keyEvents.size();
            for (int i = 0; i < len; i++) {
                usedKeyEvents.free(keyEvents.get(i));
            }
        }
        if (touchEvents.size() == 0) {
            for (int i = 0; i < deltaX.length; i++) {
                deltaX[0] = 0;
                deltaY[0] = 0;
            }
        }
        keyEvents.clear();
        touchEvents.clear();
    }
}
Also used : InputProcessor(com.badlogic.gdx.InputProcessor)

Aggregations

InputProcessor (com.badlogic.gdx.InputProcessor)6 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)2 ParticleEffect (com.badlogic.gdx.graphics.g2d.ParticleEffect)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 InputAdapter (com.badlogic.gdx.InputAdapter)1 ParticleEffectPool (com.badlogic.gdx.graphics.g2d.ParticleEffectPool)1 ParticleEmitter (com.badlogic.gdx.graphics.g2d.ParticleEmitter)1 Array (com.badlogic.gdx.utils.Array)1 Point (java.awt.Point)1