Scratch for Java

GamepadListener()

What a stage or sprite is told about the controllers, at the same point of the tick as key events (before run()): a button going down or up on any player's controller, and a controller appearing in a player's slot. Like keys, events reach listener objects even while the game is paused. A button that goes down and up between two ticks is not reported; ask Gamepad in run() for the state that stays.

public class Player extends Sprite implements GamepadListener {
  public void run() {
    this.changePosition(Gamepad.getStick(GamepadStick.LEFT).multiply(5));
  }
 
  public void whenGamepadButtonPressed(GamepadButton button) {
    if (button == GamepadButton.A) {
      this.jump();
    }
  }
}

Examples

File /src/examples/java/reference//GamepadExample.java is missing.

View on GitHub

GamepadListener()

Create Shareable URL

Select Sections