Search in sources :

Example 11 with InputAdapter

use of com.badlogic.gdx.InputAdapter 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)

Example 12 with InputAdapter

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

the class SoftKeyboardTest method create.

@Override
public void create() {
    // we want to render the input, so we need
    // a sprite batch and a font
    batch = new SpriteBatch();
    font = new BitmapFont();
    textBuffer = new SimpleCharSequence();
    // we register an InputAdapter to listen for the keyboard
    // input. The on-screen keyboard might only generate
    // "key typed" events, depending on the backend.
    Gdx.input.setInputProcessor(new InputAdapter() {

        @Override
        public boolean keyTyped(char character) {
            // convert \r to \n
            if (character == '\r')
                character = '\n';
            // if we get \b, we remove the last inserted character
            if (character == '\b' && textBuffer.length() > 0) {
                textBuffer.delete();
            }
            // else we just insert the character
            textBuffer.add(character);
            return true;
        }
    });
}
Also used : InputAdapter(com.badlogic.gdx.InputAdapter) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 13 with InputAdapter

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

the class ViewportTest2 method create.

public void create() {
    font = new BitmapFont();
    font.setColor(0, 0, 0, 1);
    Pixmap pixmap = new Pixmap(16, 16, Format.RGBA8888);
    pixmap.setColor(1, 1, 1, 1);
    pixmap.fill();
    texture = new Texture(pixmap);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    camera.position.set(100, 100, 0);
    camera.update();
    viewports = ViewportTest1.getViewports(camera);
    viewport = viewports.first();
    names = ViewportTest1.getViewportNames();
    name = names.first();
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
                name = names.get(index);
                viewport = viewports.get(index);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    });
}
Also used : InputAdapter(com.badlogic.gdx.InputAdapter) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 14 with InputAdapter

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

the class ViewportTest3 method create.

public void create() {
    modelBatch = new ModelBatch();
    modelBuilder = new ModelBuilder();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
    shadowLight = new DirectionalLight();
    shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
    environment.add(shadowLight);
    modelBatch = new ModelBatch();
    camera = new PerspectiveCamera();
    camera.fieldOfView = 67;
    camera.near = 0.1f;
    camera.far = 300f;
    camera.position.set(0, 0, 100);
    camera.lookAt(0, 0, 0);
    viewports = ViewportTest1.getViewports(camera);
    viewport = viewports.first();
    names = ViewportTest1.getViewportNames();
    name = names.first();
    ModelBuilder modelBuilder = new ModelBuilder();
    Model boxModel = modelBuilder.createBox(50f, 50f, 50f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    boxInstance = new ModelInstance(boxModel);
    boxInstance.transform.rotate(1, 0, 0, 30);
    boxInstance.transform.rotate(0, 1, 0, 30);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
                name = names.get(index);
                viewport = viewports.get(index);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    });
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) InputAdapter(com.badlogic.gdx.InputAdapter) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Model(com.badlogic.gdx.graphics.g3d.Model) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Aggregations

InputAdapter (com.badlogic.gdx.InputAdapter)14 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)9 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 Texture (com.badlogic.gdx.graphics.Texture)5 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)4 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)3 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)3 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)2 Matrix4 (com.badlogic.gdx.math.Matrix4)2 Stage (com.badlogic.gdx.scenes.scene2d.Stage)2 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)2 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)2 DisplayMode (com.badlogic.gdx.Graphics.DisplayMode)1 InputProcessor (com.badlogic.gdx.InputProcessor)1 Lwjgl3Application (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application)1 Lwjgl3ApplicationConfiguration (com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration)1 Lwjgl3Window (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window)1