com.badlogic.gdx.controllers.Controllers Java Examples

The following examples show how to use com.badlogic.gdx.controllers.Controllers. 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: SplashScreen.java    From riiablo with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: Invaders.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: EntityFactory.java    From ninja-rabbit with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new instance of {@link NinjaRabbit}, defining its graphical, audio and physical
 * properties.
 *
 * @param world
 *            The Box2D {@link World} onto which to create the {@link Body} and {@link Fixture}
 *            of the {@link Entity}.
 * @param loader
 *            A {@link BodyEditorLoader} to handle creation of the Entity body and fixtures.
 * @param assets
 *            The {@link AssetManager} from where to extract the graphical and audio resources.
 *            Those resources should be loaded in the manager before calling this method and
 *            won't be disposed.
 * @param status
 *            A reference to the global status of the player to be updated from the changes in
 *            the returned entity inner state.
 * @param observers
 *            An array of event receivers. Events will fire when the active player status
 *            changes (such as losing lives, collecting items, etc.).
 * @return A ready to use instance of a new {@link NinjaRabbit}.
 */
public static Entity createNinjaRabbit(final World world, final BodyEditorLoader loader, final AssetManager assets,
		final CurrentPlayerStatus status, final PlayerStatusObserver... observers) {
	PhysicsProcessor physics = new NinjaRabbitPhysicsProcessor();
	CONTACT_LISTENER.add(physics);
	world.setContactListener(CONTACT_LISTENER);
	GraphicsProcessor graphics = new NinjaRabbitGraphicsProcessor(assets);
	BodyProcessor bodyProcessor = new NinjaRabbitBodyProcessor(world, loader);
	AudioProcessor audio = new NinjaRabbitAudioProcessor(assets);
	PlayerStatusProcessor player = new NinjaRabbitPlayerStatusProcessor(status);
	if (observers != null) {
		for (PlayerStatusObserver o : observers) {
			player.addObserver(o);
		}
	}
	NinjaRabbit ninjaRabbit = new NinjaRabbit(player, bodyProcessor, graphics, physics, audio);

	if (Ouya.isRunningOnOuya()) {
		Controllers.clearListeners();
		Controllers.addListener(new NinjaRabbitControllerProcessor(ninjaRabbit));
	} else {
		Gdx.input.setInputProcessor(new NinjaRabbitInputProcessor(ninjaRabbit));
	}
	return ninjaRabbit;
}
 
Example #4
Source File: InGameScreen.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void exit() {
    Console console = app.getConsole();
    
    console.removeCommand("disconnect");        
    console.removeCommand("say");                
    console.removeCommand("team_say");        
    console.removeCommand("change_team");
    console.removeCommand("rcon");
    console.removeCommand("ai");
    
    Controllers.removeListener(this.controllerInput);
    
    this.dialog.destroy();
    this.sayTxtBx.destroy();
    this.teamSayTxtBx.destroy();
    this.tileSelectDialog.destroy();
}
 
Example #5
Source File: ScreenSettings.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
private Controller getController(String name) {
	for (Controller controller : Controllers.getControllers()) {
		if (controller.getName().equalsIgnoreCase(name)) {
			return controller;
		}
	}
	return null;
}
 
Example #6
Source File: ClientMaster.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
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 #7
Source File: ControllerInput.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
 */
public ControllerInput() {
    this.povDirections = new boolean[PovDirection.values().length];
    this.buttons = new boolean[64];
    this.isConnected = Controllers.getControllers().size > 0;
    this.triggerSensitivity = 0.3f;
    this.leftJoystickSensitivity = 0.2f;
    this.rightJoystickSensitivity = 0.3f;
    
    this.movements = new float[4];
}
 
Example #8
Source File: SeventhGame.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
private void initControllers() {
    Cons.println("Detecting controllers...");
    for(Controller control : Controllers.getControllers()) {
        Cons.println("Found: " + control.getName());            
    }    
    Cons.println("Completed checking for controllers");
}
 
Example #9
Source File: JamepadTest.java    From gdx-controllerutils with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #10
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean buttonX() {
    return (controllerEnabled() && Controllers
            .getControllers().get(0).getButton(99) ||
            Gdx.input.isKeyPressed(Keys.X));
}
 
Example #11
Source File: ScreenSettings.java    From RuinsOfRevenge with MIT License 4 votes vote down vote up
@Override
public void tick(float delta) {
	stage.act(delta);
	if (gamepadRead) {
		search: for (Controller pad : Controllers.getControllers()) {
			for (int i = 0; i < 4; i++) {
				if (!FloatUtils.equalsEpsilon(pad.getAxis(i), 0, 0.1f)) {
					Config.get().gamepad = pad.getName();
					gamepadButton.setText(Config.get().gamepad);
					gamepadButton.setChecked(false);
					gamepadRead = false;
					break search;
				}
			}
		}
	}
	if (gamepadButton != null) {
		if (gamepadXAxisRead) {
			for (int i = 0; i < 4; i++) {
				if (!FloatUtils.equalsEpsilon(gamepad.getAxis(i), 0f, 0.5f)) {
					Config.get().gamepadX = i;
					gamepadXAxisRead = false;
					gamepadX.setChecked(false);
					gamepadX.setText("Record");
					break;
				}
			}
		}
		if (gamepadYAxisRead) {
			for (int i = 0; i < 4; i++) {
				if (!FloatUtils.equalsEpsilon(gamepad.getAxis(i), 0f, 0.5f)) {
					Config.get().gamepadY = i;
					gamepadYAxisRead = false;
					gamepadY.setChecked(false);
					gamepadY.setText("Record");
					break;
				}
			}
		}
	}
}
 
Example #12
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean rightTrigger() {
    return (controllerEnabled() && Controllers
            .getControllers().get(0).getAxis(7) == 1);
}
 
Example #13
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean buttonY() {
    return (controllerEnabled() && Controllers
            .getControllers().get(0).getButton(100));
}
 
Example #14
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean buttonB() {
    return (controllerEnabled() && Controllers
            .getControllers().get(0).getButton(97)||
            Gdx.input.isKeyPressed(Keys.C));
}
 
Example #15
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean buttonA() {
    return (controllerEnabled() && Controllers
            .getControllers().get(0).getButton(96) ||
            Gdx.input.isKeyPressed(Keys.Z));
}
 
Example #16
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean axisDown() {
    return (controllerEnabled() && Controllers
            .getControllers().get(0).getAxis(9) == 1)
            || Gdx.input.isKeyPressed(Keys.DOWN);
}
 
Example #17
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean axisUp() {
    return (controllerEnabled() && Controllers
            .getControllers().get(0).getAxis(9) == -1)
            || Gdx.input.isKeyPressed(Keys.UP);
}
 
Example #18
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean axisRight() {
    return (controllerEnabled() && Controllers
            .getControllers().get(0).getAxis(8) == 1
            || Gdx.input.isKeyPressed(Keys.RIGHT));
}
 
Example #19
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean axisLeft() {
    return (controllerEnabled() && Controllers
            .getControllers().get(0).getAxis(8) == -1
            || Gdx.input.isKeyPressed(Keys.LEFT));
}
 
Example #20
Source File: InputController.java    From killingspree with MIT License 4 votes vote down vote up
public boolean controllerEnabled() {
    return (Controllers.getControllers().size > 0);
}
 
Example #21
Source File: SplashScreen.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void hide() {
  Controllers.removeListener(controllerListener);
  Riiablo.input.removeProcessor(inputProcessor);
  Riiablo.input.removeProcessor(stage);
}
 
Example #22
Source File: MenuScreen.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void hide() {
  Controllers.removeListener(controllerListener);
  Riiablo.input.removeProcessor(stage);
  dispose();
}