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:org.ah.gcc.rover.desktop.DesktopGCCRoverController.java

License:Open Source License

@Override
public void create() {
    // platformSpecific.init();

    String fontName = "fonts/din-alternate-bold-64.fnt";
    if (Gdx.graphics.getWidth() <= 320) {
        fontName = "fonts/din-alternate-bold-15.fnt";
    }/*from w  w  w .j a  va2s  . c o m*/

    font = new BitmapFont(Gdx.files.internal(fontName), true);
    glyphLayout = new GlyphLayout();

    font.setColor(Color.BLACK);
    batch = new SpriteBatch();
    img = new Texture("badlogic.jpg");

    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    cellSize = Gdx.graphics.getWidth() / 20;

    shapeRenderer = new ShapeRenderer();

    leftjoystick = new JoyStick((int) cellSize * 8, (int) cellSize * 4, (int) cellSize * 4);
    rightjoystick = new JoyStick((int) cellSize * 8, (int) cellSize * 16, (int) cellSize * 4);

    leftExpo = new ExpoGraph((int) cellSize * 5, (int) cellSize * 2, (int) cellSize * 2, (int) cellSize * 2);
    rightExpo = new ExpoGraph((int) cellSize * 13, (int) cellSize * 2, (int) cellSize * 2, (int) cellSize * 2);

    leftExpo.setPercentage(0.75f);
    rightExpo.setPercentage(0.90f);

    roverSelectButton = new Button((int) cellSize * 6, 0, (int) cellSize * 8, (int) (cellSize * 1.5),
            new Button.ButtonCallback() {
                @Override
                public void invoke(boolean state) {
                    if (state) {
                        int selectedRover = roverDriver.getSelectedRover().getValue() + 1;
                        if (selectedRover >= RoverHandler.ROVERS.length) {
                            selectedRover = 0;
                        }
                        roverDriver.getSelectedRover().setValue(selectedRover);
                    }
                }
            });

    pov = new POV((int) cellSize * 9, (int) cellSize * 4, (int) cellSize * 2);

    button1 = new RoundButton((int) cellSize * 6, (int) cellSize * 11, (int) cellSize / 2);

    switchLT = new SquareButton((int) cellSize * 0, (int) (cellSize * 0), (int) cellSize * 4,
            (int) cellSize * 2);
    switchLT.setState(false);
    switchLB = new Switch((int) cellSize * 0, (int) (cellSize * 2), (int) cellSize * 2, Orientation.HORIZONTAL);
    switchLB.setState(false);

    switchRT = new SquareButton((int) cellSize * 16, (int) (cellSize * 0), (int) cellSize * 4,
            (int) cellSize * 2);
    switchRT.setState(false);
    switchRB = new Switch((int) cellSize * 16, (int) (cellSize * 2), (int) cellSize * 2,
            Orientation.HORIZONTAL);
    switchRB.setState(false);

    inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(this);
    inputMultiplexer.addProcessor(new GestureDetector(this));
    Gdx.input.setInputProcessor(inputMultiplexer);

    screenController = new ScreenController();
    realController = platformSpecific.getRealController();

    screenController.setLeftJotstick(leftjoystick);
    screenController.setRightJotstick(rightjoystick);
    screenController.setHat(pov);
    screenController.setButton(switchLB, ControllerState.ButtonType.ORBIT_BUTTON);
    screenController.setButton(switchRB, ControllerState.ButtonType.LOCK_AXIS_BUTTON);
    screenController.setButton(switchLT, ControllerState.ButtonType.BOOST_BUTTON);
    screenController.setButton(switchRT, ControllerState.ButtonType.KICK_BUTTON);
    screenController.setButton(roverSelectButton, ControllerState.ButtonType.SELECT_BUTTON);

    if (realController != null) {
        comboController = new ComboController(screenController, realController);
        roverDriver = new RoverDriver(roverHandler, comboController);
    } else {
        roverDriver = new RoverDriver(roverHandler, screenController);
    }

    roverDriver.getLeftJoystick().addListener(new JoystickComponentListener() {
        @Override
        public void changed(JoystickState state) {
            leftjoystick.setValues(state.getX(), state.getY());
        }
    });

    roverDriver.getRightJoystick().addListener(new JoystickComponentListener() {
        @Override
        public void changed(JoystickState state) {
            rightjoystick.setValues(state.getX(), state.getY());
        }
    });

    roverDriver.getRoverSpeedValue().addListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            roverSpeed = evt.getNewValue().toString();
        }
    });

    roverDriver.getReadDistanceValue().addListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            roverTurningDistance = evt.getNewValue().toString();
        }
    });

    logoDrawer = new LogoDrawer(batch, camera);

    Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888);
    //Cursor customCursor = Gdx.graphics.newCursor(pixmap, 0, 0);
    //Gdx.graphics.setCursor(customCursor);
}

From source file:org.ah.gcc.rover.RoverController.java

License:Open Source License

@Override
public void create() {
    // platformSpecific.init();

    font = new BitmapFont(Gdx.files.internal("fonts/din-alternate-bold-64.fnt"), true);
    glyphLayout = new GlyphLayout();

    font.setColor(Color.BLACK);//from  w w w.  j  a v  a2s  . c  o  m
    batch = new SpriteBatch();
    img = new Texture("badlogic.jpg");

    gccimg = new Texture("GCCLogo.png");
    creativesphereimg = new Texture("creative-sphere.png");
    bobimg = new Texture("bobclub.png");

    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    cellSize = Gdx.graphics.getWidth() / 20;

    shapeRenderer = new ShapeRenderer();

    leftjoystick = new JoyStick((int) cellSize * 8, (int) cellSize * 4, (int) cellSize * 4);
    rightjoystick = new JoyStick((int) cellSize * 8, (int) cellSize * 16, (int) cellSize * 4);

    leftExpo = new ExpoGraph((int) cellSize * 8, (int) cellSize * 2, (int) cellSize * 2, (int) cellSize * 2);
    rightExpo = new ExpoGraph((int) cellSize * 10, (int) cellSize * 2, (int) cellSize * 2, (int) cellSize * 2);

    leftExpo.setPercentage(0.75f);
    rightExpo.setPercentage(0.90f);

    roverSelectButton = new Button((int) cellSize * 6, 0, (int) cellSize * 8, (int) (cellSize * 1.5),
            new Button.ButtonCallback() {
                @Override
                public void invoke(boolean state) {
                    if (state) {
                        newSelectedRover = selectedRover + 1;
                        if (newSelectedRover >= ROVERS.length) {
                            newSelectedRover = 0;
                        }
                    }
                }
            });

    button1 = new RoundButton((int) cellSize * 6, (int) cellSize * 11, (int) cellSize / 2);

    switchLT = new Switch((int) cellSize * 0, (int) (cellSize * 1), (int) cellSize * 4, Orientation.HORIZONTAL);
    switchLT.setState(true);
    switchLB = new Switch((int) cellSize * 0, (int) (cellSize * 3), (int) cellSize * 4, Orientation.HORIZONTAL);
    switchLB.setState(true);
    switch2 = new Switch((int) cellSize * 13, (int) cellSize, (int) cellSize * 2, Orientation.VERTICAL);

    inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(this);
    inputMultiplexer.addProcessor(new GestureDetector(this));
    Gdx.input.setInputProcessor(inputMultiplexer);

    screenController = new ScreenController();
    screenController.setLeftJotstick(leftjoystick);
    screenController.setRightJotstick(rightjoystick);
}

From source file:org.ams.testapps.paintandphysics.FallingBoxes.java

License:Open Source License

@Override
public void create() {
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera(10, 10 * (h / w));
    cameraNavigator = new CameraNavigator(camera);

    polygonBatch = new PrettyPolygonBatch();

    world = new PPWorld();

    bodyMover = new BodyMover(world.boxWorld, camera);

    InputMultiplexer inputMultiplexer = new InputMultiplexer();
    inputMultiplexer.addProcessor(bodyMover);
    inputMultiplexer.addProcessor(cameraNavigator);

    Gdx.input.setInputProcessor(inputMultiplexer);

    texture = new Texture("images/for packing/backgrounds-light/giftly.png");
    texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    addGround(texture);/*from   ww  w.ja  v  a 2  s  .co m*/

}

From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzle.java

License:Open Source License

/**
 * Use this to run the puzzle from another {@link ApplicationAdapter}.
 * <p/>//from ww  w. j  a v a2s .c o m
 * Remember to dispose of the atlas when you no longer use it.
 *
 * @param inputMultiplexer InputProcessors will be added to the end of the multiplexer
 * @param textureRegion    The region to draw on the puzzle.
 * @param def              defines this particular game
 */
public void create(InputMultiplexer inputMultiplexer, TextureRegion textureRegion, PhysicsPuzzleDef def,
        Callback gameOverCallback) {
    if (textureRegion == null)
        throw new IllegalArgumentException("TextureRegion is null.");
    if (def == null)
        throw new IllegalArgumentException("PhysicsPuzzleDef is null.");

    this.gameOverCallback = gameOverCallback;

    // camera stuff
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera(10, 10 * (h / w));

    cameraNavigator = new CameraNavigator(camera);
    cameraNavigator.setActive(false);

    // physics
    world = new PPWorld();
    bodyMover = new BodyMover(world.boxWorld, camera);

    // batches for drawing
    polygonBatch = new PrettyPolygonBatch();
    shapeRenderer = new ShapeRenderer();
    shapeRenderer.setAutoShapeType(true);

    // input multiplexing
    if (inputMultiplexer == null) {
        inputMultiplexer = new InputMultiplexer();
        Gdx.input.setInputProcessor(inputMultiplexer);
    }
    this.inputMultiplexer = inputMultiplexer;
    inputMultiplexer.addProcessor(bodyMover);
    inputMultiplexer.addProcessor(cameraNavigator);

    initFromDefinition(textureRegion, def);

    lookAtPuzzle();

}

From source file:org.catrobat.catroid.stage.StageListener.java

License:Open Source License

@Override
public void create() {
    font = new BitmapFont();
    font.setColor(1f, 0f, 0.05f, 1f);/*  www  .  ja  v  a 2  s  . c  om*/
    font.getData().setScale(1.2f);
    deltaActionTimeDivisor = 10f;

    shapeRenderer = new ShapeRenderer();

    project = ProjectManager.getInstance().getCurrentProject();
    scene = ProjectManager.getInstance().getSceneToPlay();
    pathForSceneScreenshot = Utils.buildScenePath(project.getName(), scene.getName()) + "/";

    virtualWidth = project.getXmlHeader().virtualScreenWidth;
    virtualHeight = project.getXmlHeader().virtualScreenHeight;

    virtualWidthHalf = virtualWidth / 2;
    virtualHeightHalf = virtualHeight / 2;

    camera = new OrthographicCamera();
    viewPort = new ExtendViewport(virtualWidth, virtualHeight, camera);
    if (batch == null) {
        batch = new SpriteBatch();
    } else {
        batch = new SpriteBatch(1000, batch.getShader());
    }
    stage = new Stage(viewPort, batch);
    initScreenMode();
    initStageInputListener();

    physicsWorld = scene.resetPhysicsWorld();

    clonedSprites = new HashSet<>();
    sprites = new ArrayList<>(scene.getSpriteList());
    boolean addPenActor = true;
    for (Sprite sprite : sprites) {
        sprite.resetSprite();
        sprite.look.createBrightnessContrastHueShader();
        stage.addActor(sprite.look);
        if (addPenActor) {
            penActor = new PenActor();
            stage.addActor(penActor);
            addPenActor = false;
        }
    }
    passepartout = new Passepartout(ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT,
            maximizeViewPortWidth, maximizeViewPortHeight, virtualWidth, virtualHeight);
    stage.addActor(passepartout);

    if (DEBUG) {
        OrthoCamController camController = new OrthoCamController(camera);
        InputMultiplexer multiplexer = new InputMultiplexer();
        multiplexer.addProcessor(camController);
        multiplexer.addProcessor(stage);
        Gdx.input.setInputProcessor(multiplexer);
        fpsLogger = new FPSLogger();
    } else {
        Gdx.input.setInputProcessor(stage);
    }
    axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp"));
    skipFirstFrameForAutomaticScreenshot = true;
    if (checkIfAutomaticScreenshotShouldBeTaken) {
        makeAutomaticScreenshot = project.manualScreenshotExists(SCREENSHOT_MANUAL_FILE_NAME)
                || scene.screenshotExists(SCREENSHOT_AUTOMATIC_FILE_NAME)
                || scene.screenshotExists(SCREENSHOT_MANUAL_FILE_NAME);
    }
    if (drawDebugCollisionPolygons) {
        collisionPolygonDebugRenderer.setProjectionMatrix(camera.combined);
        collisionPolygonDebugRenderer.setAutoShapeType(true);
        collisionPolygonDebugRenderer.setColor(Color.MAGENTA);
    }
}

From source file:org.oscim.gdx.GdxMap.java

License:Open Source License

@Override
public void create() {
    mMap = new MapAdapter();
    mMapRenderer = new MapRenderer(mMap);

    Gdx.graphics.setContinuousRendering(false);
    Gdx.app.setLogLevel(Application.LOG_DEBUG);

    int w = Gdx.graphics.getWidth();
    int h = Gdx.graphics.getHeight();

    mMap.viewport().setScreenSize(w, h);
    mMapRenderer.onSurfaceCreated();// w  ww .j  av  a 2 s  .c  om
    mMapRenderer.onSurfaceChanged(w, h);

    InputMultiplexer mux = new InputMultiplexer();
    mux.addProcessor(new InputHandler(this));
    //mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
    //                                     new MapController(mMap)));
    mux.addProcessor(new MotionHandler(mMap));

    Gdx.input.setInputProcessor(mux);

    createLayers();
}

From source file:org.oscim.theme.comparator.vtm.MapApplicationAdapter.java

License:Open Source License

@Override
public void create() {
    map = new MapAdapter() {

        @Override/*from   w  ww . ja  v  a2s . c  om*/
        public void beginFrame() {
            super.beginFrame();
        }

        @Override
        public void onMapEvent(Event e, final MapPosition mapPosition) {
            super.onMapEvent(e, mapPosition);
            if (e == Map.MOVE_EVENT || e == Map.SCALE_EVENT) {
                bothMapPositionHandler.mapPositionChangedFromVtmMap(mapPosition);
            }
        }
    };
    mapRenderer = new MapRenderer(map);
    Gdx.graphics.setContinuousRendering(true);
    Gdx.app.setLogLevel(Application.LOG_DEBUG);

    int w = Gdx.graphics.getWidth();
    int h = Gdx.graphics.getHeight();

    map.viewport().setViewSize(w, h);
    mapRenderer.onSurfaceCreated();
    mapRenderer.onSurfaceChanged(w, h);

    InputMultiplexer mux = new InputMultiplexer();
    mux.addProcessor(new MotionHandler(map) {
        @Override
        public boolean scrolled(int amount) {
            super.scrolled(amount);
            MapPosition mapPosition = map.getMapPosition();
            int zoomLevel = mapPosition.getZoomLevel() - amount;
            mapPosition.setZoomLevel(zoomLevel);
            map.setMapPosition(mapPosition);
            bothMapPositionHandler.mapPositionChangedFromVtmMap(mapPosition);
            return true;
        }
    });
    mux.addProcessor(new GestureDetector(new GestureHandlerImpl(map)));

    Gdx.input.setInputProcessor(mux);

    mapScaleBar = new DefaultMapScaleBar(map);
    mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
    mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
    mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
    mapScaleBarLayer = new MapScaleBarLayer(map, mapScaleBar);
    mapScaleBarLayer.getRenderer().setPosition(GLViewport.Position.BOTTOM_LEFT);

    centerCrossLayer = new CenterCrossLayer(map);
}

From source file:org.saltosion.pixelprophecy.Prophecy.java

License:Open Source License

@Override
public void create() {
    // Initialize InputMultiplexer
    InputMultiplexer multiplexer = new InputMultiplexer();
    Gdx.input.setInputProcessor(multiplexer);

    // Initialize GUIManager
    guiManager = new GUIManager();
    multiplexer.addProcessor(new GUIInputAdapter(guiManager));

    //Initialize StateManager
    MapLoader mapLoader = new MapLoader();
    stateManager = new StateManager();
    stateManager.addState(Names.GAME_STATE, new GameState(multiplexer, guiManager, mapLoader));
    stateManager.addState(Names.LOADING_STATE, new LoadingState(guiManager, mapLoader));
    stateManager.addState(Names.MAINMENU_STATE, new MainMenuState(guiManager));
    stateManager.setState(Names.LOADING_STATE);
}

From source file:pl.kotcrab.gdxcombat.GdxCombat.java

License:Apache License

public void changeScene(AbstractScene scene) {
    if (activeScene != null)
        activeScene.dispose();/*from w  ww. jav  a 2 s .  co m*/

    activeScene = scene;

    InputMultiplexer multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(new GestureDetector(activeScene));
    multiplexer.addProcessor(activeScene);

    Gdx.input.setInputProcessor(multiplexer);
}

From source file:pl.kotcrab.jdialogue.editor.Renderer.java

License:Open Source License

@Override
public void create() {
    Assets.load();//from w w w  . ja v a 2  s .c om

    prefs = Gdx.app.getPreferences("pl.kotcrab.dialoguelib.editorprefs");
    App.setPrefs(prefs);
    App.loadPrefs();

    camera = new OrthographicCamera(1280, 720);
    camera.position.x = 1280 / 2;
    camera.position.y = 720 / 2;
    Touch.setCamera(camera);
    cameraRect = CameraUtils.calcCameraBoundingRectangle(camera);

    shapeRenderer = new ShapeRenderer();
    batch = new SpriteBatch();

    rectangularSelection = new RectangularSelection(new RectangularSelectionListener() {
        @Override
        public void finishedDrawing(ArrayList<DComponent> matchingComponents) {
            selectedComponentsList = matchingComponents;
        }
    }, componentList);

    InputMultiplexer mul = new InputMultiplexer();
    mul.addProcessor(this);
    mul.addProcessor(new GestureDetector(this));
    mul.addProcessor(rectangularSelection);
    Gdx.input.setInputProcessor(mul);

    connectionRenderer = new ConnectionRenderer();

    infoText = new KotcrabText(Assets.consolasFont, "Load or create new project to begin!", false, 0, 0);
    infoText.setScale(1.4f);

}