Search in sources :

Example 1 with InputAdapter

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

the class InterpolationTest method create.

@Override
public void create() {
    Gdx.gl.glClearColor(.3f, .3f, .3f, 1);
    renderer = new ShapeRenderer();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    stage = new Stage(new ScreenViewport());
    resetPositions();
    Field[] interpolationFields = ClassReflection.getFields(Interpolation.class);
    // see how many fields are actually interpolations (for safety; other fields may be added with future)
    int interpolationMembers = 0;
    for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
        interpolationMembers++;
    // get interpolation names
    interpolationNames = new String[interpolationMembers];
    for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
        interpolationNames[i] = interpolationFields[i].getName();
    selectedInterpolation = interpolationNames[0];
    list = new List(skin);
    list.setItems(interpolationNames);
    list.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            selectedInterpolation = list.getSelected();
            time = 0;
            resetPositions();
        }
    });
    ScrollPane scroll = new ScrollPane(list, skin);
    scroll.setFadeScrollBars(false);
    scroll.setScrollingDisabled(true, false);
    table = new Table();
    table.setFillParent(true);
    table.add(scroll).expandX().left().width(100);
    stage.addActor(table);
    Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {

        public boolean scrolled(int amount) {
            if (!Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
                return false;
            duration -= amount / 15f;
            duration = MathUtils.clamp(duration, 0, Float.POSITIVE_INFINITY);
            return true;
        }
    }, stage, new InputAdapter() {

        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (// if "walking" was interrupted by this touch down event
            !Float.isNaN(time))
                // set startPosition to the current position
                startPosition.set(getPosition(time));
            targetPosition.set(stage.screenToStageCoordinates(targetPosition.set(screenX, screenY)));
            time = 0;
            return true;
        }
    }));
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputAdapter(com.badlogic.gdx.InputAdapter) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) Field(com.badlogic.gdx.utils.reflect.Field) Interpolation(com.badlogic.gdx.math.Interpolation) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) List(com.badlogic.gdx.scenes.scene2d.ui.List) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 2 with InputAdapter

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

the class PixmapPackerTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    shapeRenderer = new ShapeRenderer();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0);
    camera.update();
    Pixmap pixmap1 = new Pixmap(Gdx.files.internal("data/badlogic.jpg"));
    Pixmap pixmap2 = new Pixmap(Gdx.files.internal("data/particle-fire.png"));
    Pixmap pixmap3 = new Pixmap(Gdx.files.internal("data/isotile.png"));
    PixmapPacker packer = new PixmapPacker(1024, 1024, Format.RGBA8888, 8, false);
    for (int count = 1; count <= 3; ++count) {
        packer.pack("badlogic " + count, pixmap1);
        packer.pack("fire " + count, pixmap2);
        packer.pack("isotile " + count, pixmap3);
    }
    atlas = packer.generateTextureAtlas(TextureFilter.Nearest, TextureFilter.Nearest, false);
    Gdx.app.log("PixmapPackerTest", "Number of initial textures: " + atlas.getTextures().size);
    packer.setPackToTexture(true);
    for (int count = 4; count <= 10; ++count) {
        packer.pack("badlogic " + count, pixmap1);
        packer.pack("fire " + count, pixmap2);
        packer.pack("isotile " + count, pixmap3);
    }
    pixmap1.dispose();
    pixmap2.dispose();
    pixmap3.dispose();
    packer.updateTextureAtlas(atlas, TextureFilter.Nearest, TextureFilter.Nearest, false);
    textureRegions = new Array<TextureRegion>();
    packer.updateTextureRegions(textureRegions, TextureFilter.Nearest, TextureFilter.Nearest, false);
    Gdx.app.log("PixmapPackerTest", "Number of updated textures: " + atlas.getTextures().size);
    Gdx.input.setInputProcessor(new InputAdapter() {

        @Override
        public boolean keyDown(int keycode) {
            if (keycode >= Input.Keys.NUM_0 && keycode <= Input.Keys.NUM_9) {
                int number = keycode - Input.Keys.NUM_0;
                if (number < textureRegions.size) {
                    pageToShow = number;
                }
            }
            return super.keyDown(keycode);
        }
    });
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PixmapPacker(com.badlogic.gdx.graphics.g2d.PixmapPacker) InputAdapter(com.badlogic.gdx.InputAdapter) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 3 with InputAdapter

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

the class DelaunayTriangulatorTest method create.

public void create() {
    renderer = new ShapeRenderer();
    triangulate();
    System.out.println(seed);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            seed = MathUtils.random.nextLong();
            System.out.println(seed);
            triangulate();
            return true;
        }

        public boolean mouseMoved(int screenX, int screenY) {
            triangulate();
            return false;
        }
    });
}
Also used : InputAdapter(com.badlogic.gdx.InputAdapter) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 4 with InputAdapter

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

the class FilterPerformanceTest method create.

public void create() {
    batch = new SpriteBatch();
    sceneMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    textMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    atlas = new TextureAtlas(Gdx.files.internal("data/issue_pack"), Gdx.files.internal("data/"));
    texture = new Texture(Gdx.files.internal("data/resource1.jpg"), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest);
    setTextureFilter(0);
    setModeString();
    sprite = atlas.createSprite("map");
    sprite2 = new Sprite(texture, 0, 0, 855, 480);
    font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            mode++;
            if (mode == filters.length * 2)
                mode = 0;
            setTextureFilter(mode / 2);
            setModeString();
            return false;
        }
    });
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) InputAdapter(com.badlogic.gdx.InputAdapter) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 5 with InputAdapter

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

the class BitmapFontAlignmentTest method create.

@Override
public void create() {
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            renderMode = (renderMode + 1) % 6;
            return false;
        }
    });
    spriteBatch = new SpriteBatch();
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    logoSprite = new Sprite(texture);
    logoSprite.setColor(1, 1, 1, 0.6f);
    logoSprite.setBounds(50, 100, 400, 100);
    font = new BitmapFont(Gdx.files.getFileHandle("data/verdana39.fnt", FileType.Internal), Gdx.files.getFileHandle("data/verdana39.png", FileType.Internal), false);
    cache = font.newFontCache();
    layout = new GlyphLayout();
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) InputAdapter(com.badlogic.gdx.InputAdapter) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

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