Example usage for com.badlogic.gdx InputMultiplexer InputMultiplexer

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

Introduction

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

Prototype

public InputMultiplexer() 

Source Link

Usage

From source file:com.exovum.test.animation.CreditsScreen.java

License:Creative Commons License

public CreditsScreen(final Game game, Screen parentScreen) {
    this.batch = new SpriteBatch();
    this.game = game;
    this.parent = parentScreen;

    Gdx.app.log("CreditsScreen", "Creating CreditsScreen");

    menuBackground = new Texture(Gdx.files.internal("beach-ocean-sea-bg/transparent-png/full_background.png"));

    stage = new Stage(new FitViewport(800, 480));
    Gdx.input.setInputProcessor(stage);//  w w  w  . j  a  va2  s. c  om
    skin = new Skin(Gdx.files.internal("uiskin.json"));

    mainTable = new Table(skin);
    //mainTable.defaults().expand().fill().padBottom(4f).padTop(4f);
    mainTable.setFillParent(true);

    baseTable = new Table(skin);
    baseTable.defaults().expand().fill().padBottom(10f).padTop(10f);

    Label myHeader = new Label("General", skin, "small-font");
    myHeader.setColor(Color.FIREBRICK);
    myHeader.setAlignment(Align.center);

    Label myCredits = new Label("Programming and Development\n" + "Caleb Stevenson", skin, "small-font");
    myCredits.setColor(Color.BLACK);
    myCredits.setAlignment(Align.center);

    Label musicHeader = new Label("Music", skin, "small-font");
    musicHeader.setColor(Color.FIREBRICK);
    musicHeader.setAlignment(Align.center);

    Label musicCredits = new Label("\"Capre Diem\", \"Hidden Past\", \"Pixel Peeker Polka - slower\"\n"
            + "Kevin MacLeod (incompetech.com)\n" + "Licensed under Creative Commons: By Attribution 3.0\n"
            + "http://creativecommons.org/licenses/by/3.0/", skin, "small-font");
    musicCredits.setColor(Color.BLACK);
    musicCredits.setAlignment(Align.center);

    Label artHeader = new Label("Artwork", skin, "small-font");
    artHeader.setColor(Color.FIREBRICK);
    artHeader.setAlignment(Align.center);

    Label artCredits = new Label("Background and Tree Sprites\n" + "http://bevouliin.com\nopengameart.org",
            skin, "small-font");
    artCredits.setColor(Color.BLACK);

    artCredits.setAlignment(Align.center);

    TextButton exitButton = new TextButton("Back to Menu", skin, "small-font");

    Table buttonTable = new Table(skin);
    baseTable.add(myHeader).row();
    baseTable.add(myCredits).row();
    baseTable.add(musicHeader).row();
    baseTable.add(musicCredits).row();
    baseTable.add(artHeader).row();
    baseTable.add(artCredits).row();
    baseTable.add(buttonTable);
    //menuTable.setBackground("console2");
    // Set the color of the BACKGROUND on the buttons
    Color buttonColor = Color.SKY;
    exitButton.setColor(buttonColor);
    // Set the color of the TEXT on the buttons
    exitButton.getLabel().setColor(new Color(0.91f, 0.91f, 0.91f, 1));

    buttonTable.defaults().expand().fill().padBottom(4f).padTop(2f);
    buttonTable.add(exitButton).width(180f).height(60f);
    //buttonTable.padTop(20f).padBottom(20f);
    buttonTable.left();

    // Add baseTable containing buttonTable to the next row of mainTable
    //mainTable.add(buttonTable);
    mainTable.add(baseTable);
    // Add mainTable to the stage
    stage.addActor(mainTable);

    exitButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            Gdx.app.log("CreditsScreen", "Exiting to main menu");
            //game.setScreen(new AnimatorMenuScreen(game));
            //game.setScreen(parent);
            //((Game) Gdx.app.getApplicationListener()).setScreen(parent);
            ((Game) Gdx.app.getApplicationListener()).setScreen(new AnimatorMenuScreen(game));
        }
    });

    //Use an InputMultiplexer so that the Stage and keyDown input processors can both be used
    InputMultiplexer multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(stage);
    multiplexer.addProcessor(new InputAdapter() {
        // If the back key is pressed, go to main menu
        // This also handles the Android 'back' button
        @Override
        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.BACK) {
                // Handle the back button
                Gdx.app.log("CreditsScreen", "KeyDown: BACK pressed");
                //AnimatorMenuScreen newMenu = new AnimatorMenuScreen(batch, game);
                //game.setScreen(newMenu);
                //game.setScreen(parent);
                //((Game) Gdx.app.getApplicationListener()).setScreen(parent);
                ((Game) Gdx.app.getApplicationListener()).setScreen(new AnimatorMenuScreen(game));
                return true;
            }
            return false;
        }
    });

    Gdx.input.setInputProcessor(multiplexer);
}

From source file:com.gdx.EndlessGame.GameplayScreen.java

@Override
public void show() {

    Main.mixer.PlayGamePMusic(true);/*from  www. j a v  a  2 s  .c o m*/
    _controler = new VirtualControler();
    //Seteando el jugador
    _player = new PlayerVehicle(_controler);
    //setting Game managements
    _enemies = new Array<EnemyVehicle>();
    _bullets = new Array<Bullet>();
    _intersections = new Array<Intersection>();
    _weapons = new Array<Weapon>();

    //Seteando los actores y los assets
    _fireButton = new ShootingPad(_controler);
    _background = new BackgroundAnimation();
    _background.setPosition(0, _stage.getHeight());
    _sign = new SignAnimation(GraphAlgorithms.getInstance().wasNodeVisited(_graph), (int) _user.getPoints(),
            String.valueOf(_graph.getLevel()) + String.valueOf(_graph.getSeed()));

    _asteroidSpawn = new AsteroidSpawner(_stage);
    _enemySpawner = new EnemySpawner(_stage, _enemies);

    GraphAlgorithms.getInstance().generateIntersections(_graph);

    System.out.println(_graph.getNodesList().size());
    _interSpawner = new IntersectionSpawner(_stage, _graph.getNodesList().size(),
            GraphAlgorithms.getInstance().getRecommendedPath(_graph), _intersections, _weapons);

    //Agregando actores al stage
    _stage.addActor(_player);
    _player.getbBox().x = _player.getX();
    _player.getbBox().y = _player.getY();
    _stage.addActor(_fireButton);
    _stage.addActor(_background);
    _stage.addActor(_sign);

    //Seteando controladores para la entrada del usuario

    _keyboardInput = new ShipKeyboardInput(_controler);
    _touchInput = new ShipTouchInput(_controler);
    _multiplexer = new InputMultiplexer();

    //agregando los diferentes tipos de entradas definidas

    _multiplexer.addProcessor(_stage);
    _multiplexer.addProcessor(_touchInput);
    _multiplexer.addProcessor(_keyboardInput);

    Gdx.input.setInputProcessor(_multiplexer);

}

From source file:com.github.unluckyninja.defenseofhuman.DefenseOfHuman.java

License:Open Source License

@Override
public void create() {
    batch = new SpriteBatch();
    camera = new OrthographicCamera();

    batch.setProjectionMatrix(camera.combined);

    menu = new MenuScreen(batch);
    playing = new GameScreen(batch);

    playerInputController = new PlayerInputController();
    sceneInputController = new SceneInputController(menu);
    inputilexer = new InputMultiplexer();

    changeScreen(State.MENU);// w  w w .  ja  va 2  s.  c  o m

    inputilexer.addProcessor(sceneInputController);
    Gdx.input.setInputProcessor(inputilexer);
    //        Gdx.input.setCursorCatched(true);
}

From source file:com.interakt.ar.outdoor.browsing.BrowsingRenderer.java

License:Apache License

@Override
public void create() {
    Looper.prepare();/*w ww .j  a  v a2s.  co m*/

    geoMode = new BrowsingScreen(context);
    geoMode.init(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    radar = ((BrowsingMainActivity) context).getRadar();
    multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(geoMode.getGestureDetector());
    Gdx.input.setInputProcessor(multiplexer);

}

From source file:com.interakt.ar.outdoor.tagging.TaggingRenderer.java

License:Apache License

@Override
public void create() {
    Looper.prepare();/*from  www. jav a2 s . co m*/
    taggingMode = new TaggingScreen(context);
    taggingMode.init(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    ((TaggingMainActivity) context).handler.post(new Runnable() {

        @Override
        public void run() {
            ((TaggingMainActivity) context).addToBeFixed();

        }
    });
    multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(taggingMode.getGestureDetector());
    Gdx.input.setInputProcessor(multiplexer);

}

From source file:com.jmolina.orb.screens.BaseScreen.java

License:Open Source License

/**
 * Constructor//from w  w w.  ja  va 2 s.  c  om
 */
public BaseScreen(SuperManager sm) {
    superManager = sm;
    periodicTimer = 0f;
    screenFlag = new ScreenFlag();
    mainViewport = new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
    backgroundViewport = new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
    mainStage = new MainStage(mainViewport, getBackRunnable());
    backgroundStage = new BackgroundStage(getAssetManager(), backgroundViewport);
    multiplexer = new InputMultiplexer();

    mainStage.getRoot().setOrigin(VIEWPORT_WIDTH * 0.5f, VIEWPORT_HEIGHT * 0.5f);
    mainStage.getRoot().setSize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
    mainStage.getRoot().setScale(1f);
    mainStage.getRoot().setPosition(0f, 0f);

    addProcessor(mainStage);
    hierarchy = Hierarchy.LOWER;
}

From source file:com.jmstudios.pointandhit.GameScreen.java

License:Open Source License

public GameScreen(final OneShotGame game) {
    this.game = game;
    this.scale = game.scale;
    batch = new SpriteBatch();
    shapeRenderer = new ShapeRenderer();
    scoreFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_large.fnt"));
    scoreFont.setColor(Color.WHITE);
    scoreFont.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    scoreFont.setScale(scale);/*from   w  ww  .j a  v a  2s. c  o  m*/
    heartTex = new Texture(Gdx.files.internal("heart.png"));
    screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    setupMenus();

    // Set up multiplexers
    gameRunningMultiplexer = new InputMultiplexer();
    gameRunningMultiplexer.addProcessor(gameRunningStage);
    gameRunningMultiplexer.addProcessor(this);

    gamePausedMultiplexer = new InputMultiplexer();
    gamePausedMultiplexer.addProcessor(pauseStage);
    gamePausedMultiplexer.addProcessor(this);

    gameOverMultiplexer = new InputMultiplexer();
    gameOverMultiplexer.addProcessor(gameOverStage);
    gameOverMultiplexer.addProcessor(this);
}

From source file:com.jmstudios.pointandhit.OptionsScreen.java

License:Open Source License

public OptionsScreen(final OneShotGame game) {
    this.game = game;
    this.scale = game.scale;
    Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    // Font/*from  ww w  . ja  va 2s  .c  o m*/
    textFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt"));
    textFont.setScale(scale);
    BitmapFont titleFont = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_large.fnt"));
    titleFont.setScale(scale);

    // Checkbox style
    Texture checkBoxes = new Texture(Gdx.files.internal("buttons/radiobutton.png"));
    TextureRegionDrawable checkBoxUnchecked = new TextureRegionDrawable(
            new TextureRegion(checkBoxes, 0, 0, 64, 64));
    TextureRegionDrawable checkBoxChecked = new TextureRegionDrawable(
            new TextureRegion(checkBoxes, 64, 0, 64, 64));
    checkBoxStyle = new CheckBox.CheckBoxStyle(checkBoxUnchecked, checkBoxChecked, textFont, Color.WHITE);

    CheckBox verySensitive = newRadioButton("Very sensitive"), sensitive = newRadioButton("Sensitive"),
            normal = newRadioButton("Normal"), forgiving = newRadioButton("Forgiving"),
            veryForgiving = newRadioButton("Very forgiving"),
            invertControls = newRadioButton("Invert the controls");

    sensitivityGroup = new ButtonGroup<CheckBox>(verySensitive, sensitive, normal, forgiving, veryForgiving,
            invertControls);

    int startSetting = game.preferences.getInteger("sensitivity", 2);
    sensitivityGroup.uncheckAll();
    sensitivityGroup.getButtons().get(startSetting).setChecked(true);

    float padding = 20 * scale;

    // Title
    Table titleTable = new Table();
    titleTable.align(Align.topLeft);
    Pixmap backgroundPixmap = new Pixmap(1, 1, Format.RGBA8888);
    backgroundPixmap.setColor(new Color(0.9f, 0.35f, 0.1f, 1));
    backgroundPixmap.fill();
    titleTable.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(backgroundPixmap))));
    Label.LabelStyle titleLabelStyle = new Label.LabelStyle(titleFont, Color.WHITE);
    Label titleLabel = new Label("Control sensitivity", titleLabelStyle);
    titleLabel.setWrap(true);
    titleLabel.setWidth(screenSize.x - padding * 2);
    titleLabel.setAlignment(Align.center);
    titleTable.add(titleLabel).align(Align.topLeft).pad(2 * padding).width(screenSize.x - padding * 2);

    // Checkboxes
    optionsTable = new Table();
    optionsTable.align(Align.topLeft);
    optionsTable.defaults().align(Align.topLeft).pad(padding).padBottom(0).padLeft(2 * padding);
    optionsTable.row();
    optionsTable.add(verySensitive);
    optionsTable.row();
    optionsTable.add(sensitive);
    optionsTable.row();
    optionsTable.add(normal);
    optionsTable.row();
    optionsTable.add(forgiving);
    optionsTable.row();
    optionsTable.add(veryForgiving);
    optionsTable.row();
    optionsTable.add(invertControls);

    optionsTable.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            int newSensitivity = sensitivityGroup.getCheckedIndex();
            if (newSensitivity == -1)
                newSensitivity = 2;
            game.preferences.putInteger("sensitivity", newSensitivity);
            game.preferences.flush();
        }
    });

    mainTable = new Table();
    mainTable.setFillParent(true);
    mainTable.align(Align.top);
    mainTable.add(titleTable).pad(0).padBottom(padding * 4).fill(10, 1).align(Align.topLeft);
    mainTable.row();
    mainTable.add(optionsTable).align(Align.left);

    mainStage = new Stage();
    mainStage.addActor(mainTable);

    // Input
    inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(mainStage);
    inputMultiplexer.addProcessor(this);
}

From source file:com.mangecailloux.pebble.screens.Screen.java

License:Apache License

public Screen(String _name) {
    super();// w w  w. ja v  a 2  s  .  c  o  m

    if (_name != null)
        name = _name;
    else
        name = this.getClass().getSimpleName();

    manager = null;
    updaters = new Updaters();
    loaded = false;
    hasBeenActivated = false;
    inputMultiplexer = new InputMultiplexer();
}

From source file:com.mcprog.ragnar.screens.GameScreen.java

License:Apache License

/**
 * Instantiates the fields//from  ww  w.  j  av a  2  s  .  c o  m
 * Sets up stage and adds tables to it
 * @param gameInstance: Ragnar instance
 */
public GameScreen(Ragnar gameInstance) {
    super(gameInstance);

    bodies = new Array<Body>();

    bodiesToDelete = new Array<Body>();

    mobileControls = new MobileControls();

    treeBatch = new SpriteBatch();
    treeCamera = new OrthographicCamera();

    arrowHit = Gdx.audio.newSound(Gdx.files.internal("sounds/arrow-hit.mp3"));
    stage = new Stage();
    stage.setViewport(new ExtendViewport(Constants.IDEAL_WIDTH, Constants.IDEAL_HEIGHT));
    table = new GameTable();
    stage.addActor(table);
    pauseTable = new PauseTable(this);
    stage.addActor(pauseTable);

    inputMultiplexer = new InputMultiplexer();
}