com.badlogic.gdx.controllers.Controller Java Examples
The following examples show how to use
com.badlogic.gdx.controllers.Controller.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NinjaRabbitControllerProcessor.java From ninja-rabbit with GNU General Public License v2.0 | 6 votes |
@Override public boolean axisMoved(final Controller controller, final int axisIndex, final float value) { if (axisIndex == MOVE_AXIS) { float axisValue = 0.5f * value; if (Math.abs(axisValue) > Ouya.STICK_DEADZONE) { if (axisValue > 0) { character.changeState(NinjaRabbitState.RIGHT); } else { character.changeState(NinjaRabbitState.LEFT); } } else { character.changeState(NinjaRabbitState.IDLE); } } return super.axisMoved(controller, axisIndex, value); }
Example #2
Source File: ControllerMappings.java From gdx-controllerutils with Apache License 2.0 | 6 votes |
private int findHighAxisValue(Controller controller) { // Cycle through axis indexes to check if there is a high value float highestValue = 0; int axisWithHighestValue = -1; final int maxAxisIndex = controller instanceof AdvancedController ? ((AdvancedController) controller).getAxisCount() - 1 : 500; for (int i = 0; i <= maxAxisIndex; i++) { float abs = Math.abs(controller.getAxis(i)); if (abs > highestValue && abs >= analogToDigitalTreshold && abs <= maxAcceptedAnalogValue && (axisToIgnoreForRecord == null || !axisToIgnoreForRecord.contains(i))) { highestValue = abs; axisWithHighestValue = i; } } return axisWithHighestValue; }
Example #3
Source File: ControllerMappings.java From gdx-controllerutils with Apache License 2.0 | 6 votes |
protected MappedInputs getControllerMapping(Controller controller) { if (!initialized) throw new IllegalStateException("Call commitConfig() before creating Controller Listeners"); MappedInputs retVal = null; // initialize mapping map and controller information if not already present if (mappedInputs == null) mappedInputs = new HashMap<>(); retVal = mappedInputs.get(controller.getName()); // in case the controller is not recorded or loaded already, initialize it if (retVal == null) { MappedInputs defaultMapping = new MappedInputs(controller); if (getDefaultMapping(defaultMapping, controller)) { retVal = defaultMapping; mappedInputs.put(retVal.controllerName, retVal); } } return retVal; }
Example #4
Source File: SplashScreen.java From riiablo with Apache License 2.0 | 6 votes |
@Override public void show() { Controllers.addListener(controllerListener = new ControllerAdapter() { @Override public boolean buttonDown(Controller controller, int buttonIndex) { return pressToContinue(); } }); Riiablo.input.addProcessor(inputProcessor = new InputAdapter() { @Override public boolean keyDown(int keycode) { if (keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE || keycode == Input.Keys.VOLUME_DOWN || keycode == Input.Keys.VOLUME_UP) { return true; } return pressToContinue(); } @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { return pressToContinue(); } }); Riiablo.input.addProcessor(stage); }
Example #5
Source File: ControllerMappings.java From gdx-controllerutils with Apache License 2.0 | 6 votes |
/** * Some Controllers might have buttons or axis that are broken and always report a value. * Call this method before you begin to record mappings to ignore all those buttons and axis. * * @param controller controller to listen to */ public void recordButtonsToIgnoreForMapping(Controller controller) { buttonsToIgnoreForRecord = new IntSet(); axisToIgnoreForRecord = new IntSet(); int buttonFound = findPressedButton(controller); while (buttonFound >= 0) { buttonsToIgnoreForRecord.add(buttonFound); buttonFound = findPressedButton(controller); } int axisFound = findHighAxisValue(controller); while (axisFound >= 0) { axisToIgnoreForRecord.add(axisFound); axisFound = findHighAxisValue(controller); } }
Example #6
Source File: GameOver.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
public GameOver (Invaders invaders) { super(invaders); spriteBatch = new SpriteBatch(); background = new Texture(Gdx.files.internal("data/planet.jpg")); background.setFilter(TextureFilter.Linear, TextureFilter.Linear); logo = new Texture(Gdx.files.internal("data/title.png")); logo.setFilter(TextureFilter.Linear, TextureFilter.Linear); font = new BitmapFont(Gdx.files.internal("data/font16.fnt"), Gdx.files.internal("data/font16.png"), false); if (invaders.getController() != null) { invaders.getController().addListener(new ControllerAdapter() { @Override public boolean buttonUp(Controller controller, int buttonIndex) { controller.removeListener(this); isDone = true; return false; } }); } }
Example #7
Source File: MainMenu.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
public MainMenu (Invaders invaders) { super(invaders); spriteBatch = new SpriteBatch(); background = new Texture(Gdx.files.internal("data/planet.jpg")); background.setFilter(TextureFilter.Linear, TextureFilter.Linear); logo = new Texture(Gdx.files.internal("data/title.png")); logo.setFilter(TextureFilter.Linear, TextureFilter.Linear); font = new BitmapFont(Gdx.files.internal("data/font16.fnt"), Gdx.files.internal("data/font16.png"), false); if (invaders.getController() != null) { invaders.getController().addListener(new ControllerAdapter() { @Override public boolean buttonUp(Controller controller, int buttonIndex) { controller.removeListener(this); isDone = true; return false; } }); } }
Example #8
Source File: Invaders.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
@Override public void create () { Array<Controller> controllers = Controllers.getControllers(); if (controllers.size > 0) { controller = controllers.first(); } Controllers.addListener(controllerListener); setScreen(new MainMenu(this)); music = Gdx.audio.newMusic(Gdx.files.getFileHandle("data/8.12.mp3", FileType.Internal)); music.setLooping(true); music.play(); Gdx.input.setInputProcessor(new InputAdapter() { @Override public boolean keyUp (int keycode) { if (keycode == Keys.ENTER && Gdx.app.getType() == ApplicationType.WebGL) { if (!Gdx.graphics.isFullscreen()) Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayModes()[0]); } return true; } }); fps = new FPSLogger(); }
Example #9
Source File: MappedControllerAdapter.java From gdx-controllerutils with Apache License 2.0 | 5 votes |
protected boolean buttonChange(Controller controller, int buttonIndex, boolean isDown) { boolean isReverse = false; ControllerMappings.MappedInputs mapping = mappings.getControllerMapping(controller); if (mapping == null) return false; ConfiguredInput configuredInput = mapping.getConfiguredFromButton(buttonIndex); if (configuredInput == null) { configuredInput = mapping.getConfiguredFromReverseButton(buttonIndex); isReverse = true; } if (configuredInput == null) return false; switch (configuredInput.inputType) { case button: if (isDown) return configuredButtonDown(controller, configuredInput.inputId); else return configuredButtonUp(controller, configuredInput.inputId); case axis: case axisDigital: return configuredAxisMoved(controller, configuredInput.inputId, !isDown ? 0 : isReverse ? -1f : 1f); default: // axis analog may not happen Gdx.app.log(ControllerMappings.LOG_TAG, "Button mapped to analog axis not allowed!"); return false; } }
Example #10
Source File: ControllerInput.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public boolean buttonDown(Controller controller, int button) { if(button > -1 && button < this.buttons.length) this.buttons[button] = true; // System.out.println("ButtonDown:" + button); return false; }
Example #11
Source File: MappedControllerAdapter.java From gdx-controllerutils with Apache License 2.0 | 5 votes |
@Override public boolean axisMoved(Controller controller, int axisIndex, float value) { //TODO axis fires very often, so cache last controller and last two axis ControllerMappings.MappedInputs mapping = mappings.getControllerMapping(controller); if (mapping == null) return false; ConfiguredInput configuredInput = mapping.getConfiguredFromAxis(axisIndex); if (configuredInput == null) return false; switch (configuredInput.inputType) { case axis: case axisAnalog: return configuredAxisMoved(controller, configuredInput.inputId, value); case axisDigital: return configuredAxisMoved(controller, configuredInput.inputId, Math.abs(value) < analogToDigitalTreshold ? 0 : 1 * Math.signum(value)); default: // button may not happen Gdx.app.log(ControllerMappings.LOG_TAG, "Axis mapped to button not allowed!"); return false; } }
Example #12
Source File: BMControllerInputProcessor.java From beatoraja with GNU General Public License v3.0 | 5 votes |
public BMControllerInputProcessor(BMSPlayerInputProcessor bmsPlayerInputProcessor, String name, Controller controller, ControllerConfig controllerConfig) { super(bmsPlayerInputProcessor, Type.BM_CONTROLLER); this.name = name; this.controller = controller; this.setConfig(controllerConfig); }
Example #13
Source File: MappedController.java From gdx-controllerutils with Apache License 2.0 | 5 votes |
public MappedController(Controller controller, ControllerMappings mappings) { this.controller = controller; this.mappings = mappings; this.analogToDigitalTreshold = mappings.analogToDigitalTreshold; refreshMappingCache(); }
Example #14
Source File: CompositeControllerListener.java From gdx-controllerutils with Apache License 2.0 | 5 votes |
@Override public boolean ySliderMoved(final Controller controller, final int sliderCode, final boolean value) { for (ControllerListener listener : listeners) { if (listener.ySliderMoved(controller, sliderCode, value)) { return true; } } return false; }
Example #15
Source File: SeventhGame.java From seventh with GNU General Public License v2.0 | 5 votes |
private void initControllers() { Cons.println("Detecting controllers..."); for(Controller control : Controllers.getControllers()) { Cons.println("Found: " + control.getName()); } Cons.println("Completed checking for controllers"); }
Example #16
Source File: CompositeControllerListener.java From gdx-controllerutils with Apache License 2.0 | 5 votes |
@Override public boolean accelerometerMoved(final Controller controller, final int accelerometerCode, final Vector3 value) { for (ControllerListener listener : listeners) { if (listener.accelerometerMoved(controller, accelerometerCode, value)) { return true; } } return false; }
Example #17
Source File: ControllerInput.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public boolean povMoved(Controller controller, int povCode, PovDirection dir) { for(int i = 0; i<this.povDirections.length; i++) { this.povDirections[i] = false; } this.povDirections[dir.ordinal()] = true; return false; }
Example #18
Source File: CompositeControllerListener.java From gdx-controllerutils with Apache License 2.0 | 5 votes |
@Override public boolean xSliderMoved(final Controller controller, final int sliderCode, final boolean value) { for (ControllerListener listener : listeners) { if (listener.xSliderMoved(controller, sliderCode, value)) { return true; } } return false; }
Example #19
Source File: ControllerInput.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public boolean buttonUp(Controller controller, int button) { if(button > -1 && button < this.buttons.length) this.buttons[button] = false; System.out.println("ButtonUp:" + button); return false; }
Example #20
Source File: Input.java From RuinsOfRevenge with MIT License | 5 votes |
public void set(long time, Controller gamepad) { steer.set(0, 0); if (Gdx.input.isKeyPressed(Config.get().key("up"))) steer.y += 1f; if (Gdx.input.isKeyPressed(Config.get().key("down"))) steer.y -= 1f; if (Gdx.input.isKeyPressed(Config.get().key("left"))) steer.x -= 1f; if (Gdx.input.isKeyPressed(Config.get().key("right"))) steer.x += 1f; if (Config.get().enableGamepad && gamepad != null) { float xGamepad = gamepad.getAxis(Config.get().gamepadX); float yGamepad = gamepad.getAxis(Config.get().gamepadY); if (FloatUtils.equalsEpsilon(xGamepad, 0f, 0.1f)) { xGamepad = 0f; } if (FloatUtils.equalsEpsilon(yGamepad, 0f, 0.1f)) { yGamepad = 0f; } if (!FloatUtils.equalsEpsilon(xGamepad, 0, 0.1f) || !FloatUtils.equalsEpsilon(yGamepad, 0, 0.1f)) { steer.x += xGamepad; steer.y += -yGamepad; } } float len = steer.len(); len = Math.min(1f, len); steer.nor().scl(len); steerx = steer.x; steery = steer.y; }
Example #21
Source File: ControllerInput.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public boolean axisMoved(Controller controller, int axisCode, float value) { if(axisCode == 4) { triggers = value; } if(axisCode < 4) { movements[axisCode] = value; } return true; }
Example #22
Source File: JoystickGameController.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public boolean buttonDown(Controller controller, int button) { boolean result = super.buttonDown(controller, button); if(button > -1 && button < this.isButtonReleased.length) this.isButtonReleased[button] = false; return result; }
Example #23
Source File: JoystickGameController.java From seventh with GNU General Public License v2.0 | 5 votes |
@Override public boolean buttonUp(Controller controller, int button) { boolean result = super.buttonUp(controller, button); if(button > -1 && button < this.isButtonReleased.length) this.isButtonReleased[button] = true; return result; }
Example #24
Source File: NinjaRabbitControllerProcessor.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
@Override public boolean buttonDown(final Controller controller, final int buttonCode) { if (buttonCode == JUMP_KEY) { character.changeState(NinjaRabbitState.JUMP); } else if (buttonCode == RESET_KEY) { MessageManager.getInstance().dispatchMessage(null, MessageType.DEAD.code(), character); } return super.buttonDown(controller, buttonCode); }
Example #25
Source File: NinjaRabbitControllerProcessor.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
@Override public boolean buttonUp(final Controller controller, final int buttonCode) { if (buttonCode == JUMP_KEY) { character.changeState(NinjaRabbitState.IDLE); } return super.buttonUp(controller, buttonCode); }
Example #26
Source File: LibgdxGamePad.java From mini2Dx with Apache License 2.0 | 5 votes |
@Override public boolean povMoved(Controller controller, int povCode, PovDirection value) { switch(value) { case center: povs.put(povCode, PovState.CENTER); break; case north: povs.put(povCode, PovState.NORTH); break; case south: povs.put(povCode, PovState.SOUTH); break; case east: povs.put(povCode, PovState.EAST); break; case west: povs.put(povCode, PovState.WEST); break; case northEast: povs.put(povCode, PovState.NORTH_EAST); break; case southEast: povs.put(povCode, PovState.SOUTH_EAST); break; case northWest: povs.put(povCode, PovState.NORTH_WEST); break; case southWest: povs.put(povCode, PovState.SOUTH_WEST); break; } notifyPovChanged(povCode, povs.get(povCode, PovState.CENTER)); return true; }
Example #27
Source File: LibgdxGamePad.java From mini2Dx with Apache License 2.0 | 5 votes |
@Override public boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value) { if(!accelerometers.containsKey(accelerometerCode)) { accelerometers.put(accelerometerCode, new org.mini2Dx.gdx.math.Vector3(value.x, value.y, value.z)); } else { accelerometers.get(accelerometerCode).set(value.x, value.y, value.z); } notifyAccelerometerChanged(accelerometerCode); return true; }
Example #28
Source File: ClientMaster.java From RuinsOfRevenge with MIT License | 5 votes |
private Controller getController(String name) { for (Controller cont : Controllers.getControllers()) { if (cont.getName().equals(name)) { return cont; } } System.err.println("Couldn't find controller for name \"" + name + "\""); return null; }
Example #29
Source File: ScreenSettings.java From RuinsOfRevenge with MIT License | 5 votes |
private Controller getController(String name) { for (Controller controller : Controllers.getControllers()) { if (controller.getName().equalsIgnoreCase(name)) { return controller; } } return null; }
Example #30
Source File: JamepadTest.java From gdx-controllerutils with Apache License 2.0 | 5 votes |
private void refreshControllersList() { controllerNames = new Array<>(); controllers = new Array<>(); controllerNames.add("Select..."); Gdx.app.log("Controllers", Controllers.getControllers().size + " controllers connected."); for (int i = 0; i < Controllers.getControllers().size; i++) { Controller controller = Controllers.getControllers().get(i); Gdx.app.log("Controllers", controller.getName() + "/" + ((AdvancedController) controller).getUniqueId()); controllerNames.add(controller.getName()); controllers.add(controller); controller.addListener(controllerListener); } controllerList.setItems(controllerNames); controllerList.setSelectedIndex(0); }