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.o2d.pkayjava.editor.view.Overlap2DScreen.java

License:Apache License

@Override
public void show() {
    sandbox = Sandbox.getInstance();/* www  .  j a v a  2 s .c o m*/
    uiStage = sandbox.getUIStage();
    //sandboxStage = commands.getSandboxStage();

    //sandboxStage.commands = commands;

    projectManager = facade.retrieveProxy(ProjectManager.NAME);
    // check for demo project
    File demoDir = null;
    if (projectManager != null) {
        demoDir = new File(
                projectManager.getRootPath() + File.separator + "examples" + File.separator + "OverlapDemo");
    }
    //if (demoDir.isDirectory() && demoDir.exists()) {
    // TODO: temp not opening the demo
    if (false) {
        if (projectManager != null) {
            projectManager.openProjectFromPath(demoDir.getAbsolutePath() + File.separator + "project.pit");
        }
        sandbox.loadCurrentProject();
        if (sandbox.getViewport() != null) {
            sandbox.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        }
        facade.sendNotification(ProjectManager.PROJECT_OPENED);
    }
    multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(this);
    if (uiStage != null) {
        multiplexer.addProcessor(uiStage);
    }
    multiplexer.addProcessor(new SandboxInputAdapter());
    Gdx.input.setInputProcessor(multiplexer);
}

From source file:com.quadbits.gdxhelper.LWPGameModule.java

License:Apache License

@Provides
InputMultiplexer provideInputMultiplexer() {
    return new InputMultiplexer();
}

From source file:com.quadbits.gdxhelper.screens.LWPScreen.java

License:Apache License

public LWPScreen(LWPGame game) {
    // Game/*  w  w w . j  av  a2 s . co m*/
    this.game = game;

    // Input processing
    inputMultiplexer = new InputMultiplexer();
    gestureDetector = new GestureDetector(this);
    gestureDetector.setTapSquareSize(32 * Gdx.graphics.getDensity());

    panningEnabled = game.isPanningEnabled();
    flingEnabled = game.isFlingEnabled();
    flingVelocityX = 0;
    flingVelocityY = 0;
    flingDampFactor = DEFAULT_FLING_DAMP_FACTOR;

    // Rendering
    renderCount = 0;
    maxSleepTimeMillis = 0;
    maxDeltaTime = DEFAULT_MAX_DELTA_TIME_MILLIS;
    continuousRendering = false;

    // Scroll
    scrollXChangeListeners = new ArrayList<ScrollChangeListener>();
    scrollYChangeListeners = new ArrayList<ScrollChangeListener>();
    scrollX = 0.5f;
    scrollY = 0.5f;

    // Shaders
    etc1Shader = null;
    etc1aShader = null;
    defaultShader = DefaultShader.NONE;
}

From source file:com.qualcomm.vuforia.samples.libGDX.screens.ChooseBallScreen.java

License:Apache License

@Override
public void create() {
    if (app.createServerScreen.create != null) {
        app.createServerScreen.create.resetUserChoiceState();
        app.createServerScreen.create.startBallsDistribute();
    } else if (app.joinServerScreen.join != null) {
        PropertiesSingleton.getInstance()
                .initRandomCoinPosition(PropertiesSingleton.getInstance().getChosenIsland());
        //PropertiesSingleton.getInstance().initRandomPowerupPosition(PropertiesSingleton.getInstance().getChosenIsland());
    }/* w  w  w.  ja  va2s  .c o m*/

    modelBatch = new ModelBatch();

    fps = new FPSLogger();
    Gdx.app.log("height: " + Gdx.graphics.getHeight() + "", "width: " + Gdx.graphics.getWidth() + "");

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f,
            0.8f, -1f, -.8f, -.2f));
    environment.shadowMap = shadowLight;

    shadowBatch = new ModelBatch(new DepthShaderProvider());

    cam = new VuforiaCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();

    instances = new Array<ModelInstance>();
    //       instances.add(new ModelInstance(model, "floor"));
    //        instances.add(ball = new Ball(model, "ball"));
    //        ball.setPosition(1f, 1f, 1f);

    this.stage = new Stage(new StretchViewport(Gdx.graphics.getHeight(), Gdx.graphics.getHeight()));

    initFonts();
    //        BitmapFont font = new BitmapFont();
    Label.LabelStyle labelStyle = new Label.LabelStyle(app.font60, Color.WHITE);
    Label.LabelStyle labelStyle2 = new Label.LabelStyle(app.font60, Color.WHITE);
    Label labelTitle = new Label("CHOOSE BALL ", labelStyle);
    LabelScore = new Label("apple", labelStyle2);
    //        labelTitle.setScale(Gdx.graphics.getWidth() / 10, Gdx.graphics.getHeight() / 10);
    Gdx.app.log("width: " + Gdx.graphics.getWidth(), "height: " + Gdx.graphics.getHeight());
    labelTitle.setPosition(Gdx.graphics.getHeight() / 2 - labelTitle.getWidth() / 2,
            Gdx.graphics.getHeight() - labelTitle.getHeight() * 2);

    LabelScore.setPosition(Gdx.graphics.getHeight() - (LabelScore.getWidth() + Gdx.graphics.getHeight() / 50),
            LabelScore.getHeight() / 2);

    swipe = new Image(new Sprite(new Texture(Gdx.files.internal("swipe2.png"))));
    swipe.addAction(Actions.sequence(Actions.fadeOut(0.00000001f), Actions.delay(2), Actions.fadeIn(1)));
    //        swipe.setSize((stage.getWidth()) / 6, stage.getHeight() / 6);
    swipe.setPosition(Gdx.graphics.getHeight() / 2 - swipe.getWidth() / 2,
            Gdx.graphics.getHeight() / 2 - swipe.getHeight() / 2);
    stage.addActor(swipe);

    accept = new Image(new Sprite(new Texture(Gdx.files.internal("accept.png"))));
    //        accept.addAction(Actions.sequence(Actions.fadeOut(0.00000001f), Actions.delay(2), Actions.fadeIn(1)));
    accept.setSize((stage.getWidth()) / 10, stage.getWidth() / 10);
    accept.setPosition(Gdx.graphics.getHeight() / 2 - accept.getWidth() / 2, accept.getHeight());
    //        stage.addActor(accept);

    stage.addActor(LabelScore);
    stage.addActor(labelTitle);

    TextureAtlas atlasVote = new TextureAtlas("Buttons.pack");

    Skin voteSkin = new Skin(atlasVote);

    ImageButton.ImageButtonStyle voteButtonStyle = new ImageButton.ImageButtonStyle(); //Instaciate
    voteButtonStyle.up = voteSkin.getDrawable("ready"); //Set image for not pressed button
    voteButtonStyle.checked = voteSkin.getDrawable("notready"); //Set image for not pressed button

    readyButton = new ImageButton(voteButtonStyle);

    readyButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (app.joinServerScreen.join != null) {
                app.joinServerScreen.join.sendBallChoice(ballNames.get(currentBall));
            } else if (app.createServerScreen.create != null) {
                app.createServerScreen.create.serverUser.setBallChoice(ballNames.get(currentBall));
                app.createServerScreen.create.serverUser.setChosen(true);
                app.createServerScreen.create.notifyBalls();
            }
        }
    });

    readyButton.setSize((stage.getWidth()) / 5, stage.getWidth() / 10);

    readyButton.setPosition(Gdx.graphics.getHeight() / 2 - readyButton.getWidth() / 2, 0);
    stage.addActor(readyButton);

    for (int i = 0; i < ballNames.size; i++) {
        Model tmpModel = assets.get("3d/balls/" + ballNames.get(i) + ".g3db", Model.class);

        for (int k = 0; k < tmpModel.meshes.size; k++)
            tmpModel.meshes.get(k).scale(5, 5, 5);
        //            String id = tmpModel.nodes.get(0).id;
        //            Node node = tmpModel.getNode(id);
        //            node.scale.set(30f, 30f, 30f);
        //            node.translation.set(0, 15f, 0);
        //            tmpModel.calculateTransforms();
        instances.add(new ModelInstance(tmpModel));
    }

    InputMultiplexer inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(stage);
    inputMultiplexer.addProcessor(new GestureDetector(0.0f, 0.0f, 0.0f, 5f, this));
    Gdx.input.setInputProcessor(inputMultiplexer);
}

From source file:com.qualcomm.vuforia.samples.libGDX.screens.ChooseIslandScreen.java

License:Apache License

@Override
public void create() {
    if (app.createServerScreen.create != null) {
        app.createServerScreen.create.resetUserChoiceState();
        app.createServerScreen.create.startIslandVote();
    }/*from ww  w. j  a  va 2s  .  c  om*/

    modelBatch = new ModelBatch();

    fps = new FPSLogger();
    Gdx.app.log("height: " + Gdx.graphics.getHeight() + "", "width: " + Gdx.graphics.getWidth() + "");

    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 1f, 1f));
    //        environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    //        environment.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -1f, -.8f,
    //                -.2f));
    //        environment.shadowMap = shadowLight;

    shadowBatch = new ModelBatch(new DepthShaderProvider());

    cam = new VuforiaCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();

    instances = new Array<ModelInstance>();
    voteButtons = new Array<ImageButton>();

    this.stage = new Stage(new StretchViewport(Gdx.graphics.getHeight(), Gdx.graphics.getHeight()));

    initFonts();
    //        BitmapFont font = new BitmapFont();
    Label.LabelStyle labelStyle = new Label.LabelStyle(app.font60, Color.WHITE);
    Label.LabelStyle labelStyle2 = new Label.LabelStyle(app.font60, Color.WHITE);
    Label labelTitle = new Label("CHOOSE ISLAND ", labelStyle);
    LabelScore = new Label("forest", labelStyle2);
    //        labelTitle.setScale(Gdx.graphics.getWidth() / 10, Gdx.graphics.getHeight() / 10);
    Gdx.app.log("width: " + Gdx.graphics.getWidth(), "height: " + Gdx.graphics.getHeight());
    labelTitle.setPosition(Gdx.graphics.getHeight() / 2 - labelTitle.getWidth() / 2,
            Gdx.graphics.getHeight() - labelTitle.getHeight() * 2);

    LabelScore.setPosition(Gdx.graphics.getHeight() - (LabelScore.getWidth() + Gdx.graphics.getHeight() / 50),
            LabelScore.getHeight() / 2);

    swipe = new Image(new Sprite(new Texture(Gdx.files.internal("swipe2.png"))));
    swipe.addAction(Actions.sequence(Actions.fadeOut(0.00000001f), Actions.delay(2), Actions.fadeIn(1)));
    //        swipe.setSize((stage.getWidth()) / 6, stage.getHeight() / 6);
    swipe.setPosition(Gdx.graphics.getHeight() / 2 - swipe.getWidth() / 2,
            Gdx.graphics.getHeight() / 2 - swipe.getHeight() / 2);
    stage.addActor(swipe);

    accept = new Image(new Sprite(new Texture(Gdx.files.internal("accept.png"))));
    accept.setSize((stage.getWidth()) / 10, stage.getWidth() / 10);
    accept.setPosition(Gdx.graphics.getHeight() / 2 - accept.getWidth() / 2, accept.getHeight());

    stage.addActor(LabelScore);
    stage.addActor(labelTitle);

    TextureAtlas atlasVote = new TextureAtlas("Buttons.pack");

    Skin voteSkin = new Skin(atlasVote);

    ImageButton.ImageButtonStyle voteButtonStyle = new ImageButton.ImageButtonStyle(); //Instaciate
    voteButtonStyle.up = voteSkin.getDrawable("notvoted"); //Set image for not pressed button
    voteButtonStyle.checked = voteSkin.getDrawable("voted"); //Set image for pressed

    for (int i = 0; i < islandNames.size; i++) {
        Model tmpModel = assets.get("3d/islands/" + islandNames.get(i) + ".g3db", Model.class);
        //            tmpModel.meshes.get(0).scale(3,3,3);
        //            Texture texture2 = new Texture(Gdx.files.internal("3d/islands/"+islandNames.get(i)+".jpg"), Pixmap.Format.RGB888, false);
        //            TextureAttribute textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture2);
        //            Material material = tmpModel.materials.get(0);
        //            material.set(textureAttribute);
        instances.add(new ModelInstance(tmpModel));
    }

    int numberOfIslands = islandNames.size;
    for (int i = 0; i < numberOfIslands; i++) {
        ImageButton item1Button = new ImageButton(voteButtonStyle);
        item1Button.setSize((stage.getWidth()) / 10, stage.getWidth() / 6);

        //        Gdx.input.setInputProcessor(stage);

        item1Button.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                voted = islandNames.get(currentIsland);
                if (app.joinServerScreen.join != null) {
                    app.joinServerScreen.join.sendIslandChoice(voted);
                } else if (app.createServerScreen != null) {
                    app.createServerScreen.create.serverUser.setIslandChoice(voted);
                    app.createServerScreen.create.serverUser.setChosen(true);
                    app.createServerScreen.create.notifyIsland();
                }
                //boolean found = false;
                /*for(int k = 0; k < voted.size; k++)
                {
                if(voted.get(k) == islandNames.get(currentIsland))
                    found = true;
                }
                        
                if(!found)
                voted.add(islandNames.get(currentIsland));
                        
                Gdx.app.log("voted", voted + "");
                        
                PropertiesSingleton.getInstance().setChoosenIsland(islandNames.get(currentIsland));*/

                //app.setScreen(new ChooseBallScreen(app));
            }
        });

        item1Button.setPosition(0, -item1Button.getHeight());
        voteButtons.add(item1Button);
        stage.addActor(voteButtons.get(i));
    }

    voteButtons.get(currentIsland).setPosition(Gdx.graphics.getHeight() / 2 - accept.getWidth() / 2,
            accept.getHeight());

    InputMultiplexer inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(stage);
    inputMultiplexer.addProcessor(new GestureDetector(0.0f, 0.0f, 0.0f, 5f, this));
    Gdx.input.setInputProcessor(inputMultiplexer);
}

From source file:com.ray3k.libraryinvaders.states.GameState.java

License:Open Source License

@Override
public void start() {
    EnemyEntity.speedMultiplier = 1.0f;//from  w  w  w  .j  ava  2  s.  c o  m
    respawnTimer = -1;
    score = 0;

    ufoTimer = UFO_MAX_TIME;

    inputManager = new InputManager();

    camera = new OrthographicCamera();
    viewport = new ScreenViewport(camera);
    viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    viewport.apply();

    camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0);

    skin = getCore().getAssetManager().get(Core.DATA_PATH + "/skin/skin.json", Skin.class);
    stage = new Stage(new ScreenViewport());

    InputMultiplexer inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(inputManager);
    inputMultiplexer.addProcessor(stage);
    Gdx.input.setInputProcessor(inputMultiplexer);

    table = new Table();
    table.setFillParent(true);
    stage.addActor(table);

    entityManager = new EntityManager();
    PlayerEntity player = new PlayerEntity(this);

    spawnEntities();

    Array<BarricadeEntity> barricades = new Array<BarricadeEntity>();
    float barricadesWidth = 0.0f;
    final int BARRICADE_COUNT = 4;
    for (int i = 0; i < BARRICADE_COUNT; i++) {
        BarricadeEntity barricade = new BarricadeEntity(this);
        Array<String> names = getCore().getImagePacks().get(Core.DATA_PATH + "/barricades");
        barricade.setTextureRegion(getCore().getAtlas().findRegion(names.random()));

        barricade.setX(barricadesWidth);
        barricade.setY(30.0f + player.getTextureRegion().getRegionHeight() + 35.0f);

        barricadesWidth += barricade.getTextureRegion().getRegionWidth();

        barricades.add(barricade);
    }

    final float GAP = (Gdx.graphics.getWidth() - barricadesWidth - 100.0f) / (BARRICADE_COUNT - 1);

    for (int i = 1; i < barricades.size; i++) {
        BarricadeEntity barricade = barricades.get(i);
        barricade.addX(GAP * i);
        barricadesWidth += GAP;
    }

    final float addX = (Gdx.graphics.getWidth() - barricadesWidth) / 2.0f;
    for (BarricadeEntity barricade : barricades) {
        barricade.addX(addX);
        subdivideBarricade(barricade);
    }

    createStageElements();
}

From source file:com.sidereal.dolphinoes.architecture.core.input.Input.java

License:Apache License

/** Constructor for input, does not have any connection to the LibGDX backend yet. Is called in
 * {@link DolphinOES#DolphinOES(com.sidereal.dolphinoes.architecture.GameScene, DolphinOESConfiguration)}. */
public Input() {/*from   w w w .ja  v  a  2  s  .  co  m*/

    inputData = new ObjectMap<Integer, ActionData>();
    touchInputData = new ObjectMap<Integer, TouchData>();

    inputMultiplexer = new InputMultiplexer();
    inputProcessors = new ObjectMap<String, InputProcessor>();

    actionEvents = new ObjectMap<InputProcessor, Array<ActionEventWrapper>>();
    touchEvents = new ObjectMap<InputProcessor, Array<TouchEventWrapper>>();
    scrollEvents = new ObjectMap<InputProcessor, Array<ScrollEvent>>();
    keyTypedEvents = new ObjectMap<InputProcessor, Array<KeyTypedEvent>>();

    // contains all of the Events on down, up or release

}

From source file:com.steelkiwi.patheditor.gdx.GdxScreen.java

License:Apache License

public GdxScreen(GdxApp gdxApp, int stageW, int stageH, int canvasW, int canvasH) {
    super(gdxApp);
    this.screenW = stageW;
    this.screenH = stageH;

    camera = new Camera(canvasW, canvasH);
    camera.position.x = (int) (screenW / 2);
    camera.position.y = (int) (screenH / 2);

    stage = new Stage(stageW, stageH, false);
    stage.setCamera(camera);//from w ww  .  j  a va 2 s. co m

    bgDrawer = new BGDrawer();

    inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(stage);
    inputMultiplexer.addProcessor(new InputHandler());
    Gdx.input.setInputProcessor(inputMultiplexer);
}

From source file:com.strategames.engine.screens.AbstractScreen.java

License:Open Source License

public InputMultiplexer getMultiplexer() {
    if (this.multiplexer == null) {
        this.multiplexer = new InputMultiplexer();
    }//  www.j  a va  2  s.  com
    return this.multiplexer;
}

From source file:com.strongjoshua.console.GUIConsole.java

License:Apache License

@Override
public void resetInputProcessing() {
    usesMultiplexer = true;//  w w w.  j  av  a 2s.c  o  m
    appInput = Gdx.input.getInputProcessor();
    if (appInput != null) {
        if (hasStage(appInput)) {
            log("Console already added to input processor!", LogLevel.ERROR);
            Gdx.app.log("Console", "Already added to input processor!");
            return;
        }
        multiplexer = new InputMultiplexer();
        multiplexer.addProcessor(stage);
        multiplexer.addProcessor(appInput);
        Gdx.input.setInputProcessor(multiplexer);
    } else {
        Gdx.input.setInputProcessor(stage);
    }
}