Search in sources :

Example 1 with InputProcessor

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

the class ParticleEmitterTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    effect = new ParticleEffect();
    effect.load(Gdx.files.internal("data/test.p"), Gdx.files.internal("data"));
    effect.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    // Of course, a ParticleEffect is normally just used, without messing around with its emitters.
    emitters = new Array(effect.getEmitters());
    effect.getEmitters().clear();
    effect.getEmitters().add(emitters.get(0));
    inputProcessor = new InputProcessor() {

        public boolean touchUp(int x, int y, int pointer, int button) {
            return false;
        }

        public boolean touchDragged(int x, int y, int pointer) {
            effect.setPosition(x, Gdx.graphics.getHeight() - y);
            return false;
        }

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            // effect.setPosition(x, Gdx.graphics.getHeight() - y);
            ParticleEmitter emitter = emitters.get(emitterIndex);
            particleCount += 100;
            System.out.println(particleCount);
            particleCount = Math.max(0, particleCount);
            if (particleCount > emitter.getMaxParticleCount())
                emitter.setMaxParticleCount(particleCount * 2);
            emitter.getEmission().setHigh(particleCount / emitter.getLife().getHighMax() * 1000);
            effect.getEmitters().clear();
            effect.getEmitters().add(emitter);
            return false;
        }

        public boolean keyUp(int keycode) {
            return false;
        }

        public boolean keyTyped(char character) {
            return false;
        }

        public boolean keyDown(int keycode) {
            ParticleEmitter emitter = emitters.get(emitterIndex);
            if (keycode == Input.Keys.DPAD_UP)
                particleCount += 5;
            else if (keycode == Input.Keys.DPAD_DOWN)
                particleCount -= 5;
            else if (keycode == Input.Keys.SPACE) {
                emitterIndex = (emitterIndex + 1) % emitters.size;
                emitter = emitters.get(emitterIndex);
                // if we've previously stopped the emitter reset it
                if (emitter.isComplete())
                    emitter.reset();
                particleCount = (int) (emitter.getEmission().getHighMax() * emitter.getLife().getHighMax() / 1000f);
            } else if (keycode == Input.Keys.ENTER) {
                emitter = emitters.get(emitterIndex);
                if (emitter.isComplete())
                    emitter.reset();
                else
                    emitter.allowCompletion();
            } else
                return false;
            particleCount = Math.max(0, particleCount);
            if (particleCount > emitter.getMaxParticleCount())
                emitter.setMaxParticleCount(particleCount * 2);
            emitter.getEmission().setHigh(particleCount / emitter.getLife().getHighMax() * 1000);
            effect.getEmitters().clear();
            effect.getEmitters().add(emitter);
            return false;
        }

        @Override
        public boolean mouseMoved(int x, int y) {
            return false;
        }

        @Override
        public boolean scrolled(int amount) {
            return false;
        }
    };
    Gdx.input.setInputProcessor(inputProcessor);
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect) Array(com.badlogic.gdx.utils.Array) ParticleEmitter(com.badlogic.gdx.graphics.g2d.ParticleEmitter) InputProcessor(com.badlogic.gdx.InputProcessor) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 2 with InputProcessor

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

the class LwjglAWTInput 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) {
            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);
                        break;
                }
                usedTouchEvents.free(e);
            }
        } else {
            int len = touchEvents.size();
            for (int i = 0; i < len; i++) {
                TouchEvent event = touchEvents.get(i);
                if (event.type == TouchEvent.TOUCH_DOWN)
                    justTouched = true;
                usedTouchEvents.free(event);
            }
            len = keyEvents.size();
            for (int i = 0; i < len; i++) {
                usedKeyEvents.free(keyEvents.get(i));
            }
        }
        if (touchEvents.size() == 0) {
            deltaX = 0;
            deltaY = 0;
        }
        keyEvents.clear();
        touchEvents.clear();
    }
}
Also used : InputProcessor(com.badlogic.gdx.InputProcessor) Point(java.awt.Point)

Example 3 with InputProcessor

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

the class LwjglInput method processEvents.

void processEvents() {
    synchronized (this) {
        if (processor != null) {
            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);
                        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);
                        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++) {
                usedTouchEvents.free(touchEvents.get(i));
            }
            len = keyEvents.size();
            for (int i = 0; i < len; i++) {
                usedKeyEvents.free(keyEvents.get(i));
            }
        }
        keyEvents.clear();
        touchEvents.clear();
    }
}
Also used : InputProcessor(com.badlogic.gdx.InputProcessor)

Example 4 with InputProcessor

use of com.badlogic.gdx.InputProcessor in project libgdx-inGameConsole by StrongJoshua.

the class GUIConsole method hasStage.

/**
 * Compares the given processor to the console's stage. If given a multiplexer, it is iterated through recursively to check all
 * of the multiplexer's processors for comparison.
 *
 * @param processor
 * @return processor == this.stage
 */
private boolean hasStage(InputProcessor processor) {
    if (!(processor instanceof InputMultiplexer)) {
        return processor == stage;
    }
    InputMultiplexer im = (InputMultiplexer) processor;
    Array<InputProcessor> ips = im.getProcessors();
    for (InputProcessor ip : ips) {
        if (hasStage(ip)) {
            return true;
        }
    }
    return false;
}
Also used : InputMultiplexer(com.badlogic.gdx.InputMultiplexer) InputProcessor(com.badlogic.gdx.InputProcessor)

Example 5 with InputProcessor

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

the class ParticleEmittersTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    effect = new ParticleEffect();
    effect.load(Gdx.files.internal("data/singleTextureAllAdditive.p"), Gdx.files.internal("data"));
    effect.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    effectPool = new ParticleEffectPool(effect, 20, 20);
    setupUI();
    InputProcessor inputProcessor = new InputAdapter() {

        public boolean touchDragged(int x, int y, int pointer) {
            if (latestEffect != null)
                latestEffect.setPosition(x, Gdx.graphics.getHeight() - y);
            return false;
        }

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            latestEffect = effectPool.obtain();
            latestEffect.setEmittersCleanUpBlendFunction(!skipCleanup.isChecked());
            latestEffect.setPosition(x, Gdx.graphics.getHeight() - y);
            effects.add(latestEffect);
            return false;
        }
    };
    InputMultiplexer multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(ui);
    multiplexer.addProcessor(inputProcessor);
    Gdx.input.setInputProcessor(multiplexer);
}
Also used : ParticleEffect(com.badlogic.gdx.graphics.g2d.ParticleEffect) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) InputAdapter(com.badlogic.gdx.InputAdapter) ParticleEffectPool(com.badlogic.gdx.graphics.g2d.ParticleEffectPool) InputProcessor(com.badlogic.gdx.InputProcessor) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

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