Example usage for com.badlogic.gdx InputMultiplexer addProcessor

List of usage examples for com.badlogic.gdx InputMultiplexer addProcessor

Introduction

In this page you can find the example usage for com.badlogic.gdx InputMultiplexer addProcessor.

Prototype

public void addProcessor(InputProcessor processor) 

Source Link

Usage

From source file:se.danielj.geometridestroyer.GeometriDestroyer.java

License:GNU General Public License

public GeometriDestroyer(Core core, InputMultiplexer inputMultiplexer) {
    this.core = core;

    camera = new OrthographicCamera(Constants.WIDTH, Constants.HEIGHT);
    camera.position.set(Constants.WIDTH / 2, Constants.HEIGHT / 2, 0);
    camera.update();//from   w w w  .ja v a  2 s  .  c o m
    batch = new SpriteBatch();

    world = new World(new Vector2(0, -40), true);

    stage = new IngameStage(core, world, this);
    inputMultiplexer.addProcessor(this);
    inputMultiplexer.addProcessor(stage);

    world.setContactListener(new ContactListener() {
        @Override
        public void beginContact(Contact contact) {
            Object a = contact.getFixtureA().getBody().getUserData();
            Object b = contact.getFixtureB().getBody().getUserData();
            if (a instanceof Entity && b instanceof Entity) {
                return;
            }
            if ((a instanceof Entity && ((Entity) a).isPlayer())
                    || (b instanceof Entity && ((Entity) b).isPlayer())) {
                gameOver();
            }
        }

        @Override
        public void endContact(Contact contact) {
        }

        @Override
        public void preSolve(Contact contact, Manifold oldManifold) {
        }

        @Override
        public void postSolve(Contact contact, ContactImpulse impulse) {
        }
    });

    victoryChecker = new NullVictoryChecker();

    pauseRenderer = new Renderer() {
        @Override
        public void render() {
            Gdx.gl.glClearColor(1, 1, 1, 1);
            Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

            batch.setProjectionMatrix(camera.combined);
            batch.begin();
            batch.draw(SpriteManager.getSprite(Sprites.BACKGROUND), 0, 0, Constants.WIDTH, Constants.HEIGHT);
            Iterator<Body> i = world.getBodies();
            while (i.hasNext()) {
                // Draw entities
                Body body = i.next();
                if (body.getUserData() instanceof Entity) {
                    Entity entity = (Entity) body.getUserData();
                    entity.draw(batch, body);
                }
            }
            batch.end();

            // Check if victory
            victoryChecker.check();

            stage.act();
            stage.draw();
        }
    };

    normalRenderer = new Renderer() {
        @Override
        public void render() {
            world.step(1 / 60f, 6, 2);

            Gdx.gl.glClearColor(1, 1, 1, 1);
            Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

            batch.setProjectionMatrix(camera.combined);
            batch.begin();
            batch.draw(SpriteManager.getSprite(Sprites.BACKGROUND), 0, 0, Constants.WIDTH, Constants.HEIGHT);
            Iterator<Body> i = world.getBodies();
            while (i.hasNext()) {
                // Draw entities
                Body body = i.next();
                if (body.getUserData() instanceof Entity) {
                    Entity entity = (Entity) body.getUserData();
                    entity.draw(batch, body);
                }
            }
            batch.end();

            // Check if victory
            victoryChecker.check();

            stage.act();
            stage.draw();
        }
    };

    renderer = normalRenderer;
}

From source file:se.danielj.geometridestroyer.LevelScreen.java

License:GNU General Public License

public LevelScreen(final Core core, InputMultiplexer inputMultiplexer) {
    this.core = core;
    stage = new Stage();
    stage.setViewport(Constants.STAGE_WIDTH, Constants.STAGE_HEIGHT, false);

    camera = new OrthographicCamera(Constants.WIDTH, Constants.HEIGHT);
    camera.position.set(Constants.WIDTH / 2, Constants.HEIGHT / 2, 0);
    camera.update();/*  w  ww .j  ava 2  s .c  om*/

    batch = new SpriteBatch();

    inputMultiplexer.addProcessor(stage);
    inputMultiplexer.addProcessor(this);

    Table table = new Table();
    for (int i = 1; i <= GeometriDestroyer.numberOfLevels; ++i) {
        table.row();
        table.add(new LevelButton(i)).height(80);
    }
    ScrollPane scrollPane = new ScrollPane(table);
    scrollPane.setPosition(0, 50);
    scrollPane.setSize(600, 620);
    scrollPane.setFadeScrollBars(false);
    ScrollPaneStyle scrollPaneStyle = new ScrollPaneStyle();
    scrollPaneStyle.vScrollKnob = new TextureRegionDrawable(
            SpriteManager.getSprite(SpriteManager.Sprites.SCROLL));
    scrollPaneStyle.vScroll = new TextureRegionDrawable(
            SpriteManager.getSprite(SpriteManager.Sprites.SCROLL_BG));
    scrollPane.setStyle(scrollPaneStyle);
    stage.addActor(scrollPane);

    LabelStyle style = new LabelStyle();
    style.font = FontManager.getTitleFont();
    style.fontColor = new Color(1, 1, 1, 1);
    Label title = new Label("Geometri\nDestroyer", style);
    title.setPosition(650, 400);
    stage.addActor(title);

    final TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = FontManager.getNormalFont();
    textButtonStyle.up = new TextureRegionDrawable(SpriteManager.getSprite(SpriteManager.Sprites.BLANK));
    textButtonStyle.down = new TextureRegionDrawable(SpriteManager.getSprite(SpriteManager.Sprites.BLANK));
    textButtonStyle.fontColor = new Color(0.9f, 0.5f, 0.5f, 1);
    textButtonStyle.downFontColor = new Color(0, 0.4f, 0, 1);

    TextButton button = new TextButton("Credits", textButtonStyle);
    button.setPosition(700, 100);
    button.addListener(new InputListener() {
        private boolean pressed = false;

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            pressed = true;
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (pressed) {
                LevelScreen.this.core.setScreen(core.credits);
            }
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            pressed = ((TextButton) event.getListenerActor()).isPressed();
        }
    });
    stage.addActor(button);
}

From source file:se.danielj.skuttandenyancat.systems.PlayerInputSystem.java

License:GNU General Public License

@SuppressWarnings("unchecked")
public PlayerInputSystem(InputMultiplexer inputMultiplexer, GameController gameController) {
    super(Aspect.getAspectForAll(Velocity.class, Player.class));
    inputMultiplexer.addProcessor(this);
    this.gameController = gameController;
}

From source file:stray.HelpScreen.java

License:Creative Commons License

@Override
public void show() {
    InputMultiplexer p = main.getDefaultInput();
    p.addProcessor(new HelpInputProcessor(main, this));
    Gdx.input.setInputProcessor(p);/*w ww.ja va  2s  .  co m*/
}