Class GamepadState

java.lang.Object
org.openpatch.scratch.gamepad.GamepadState

public final class GamepadState extends Object
What the controllers were like at one point in time: every player slot's buttons, sticks and triggers. Not part of the learner API: the extension fills one per poll on the window thread, and the game thread's copy is what learners read.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The player slots, 1 to 4 in joystick-slot order.
  • Constructor Summary

    Constructors
    Constructor
    Description
    No controller connected, nothing pressed, sticks and triggers at rest.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Empties the whole state.
    boolean
    connected(int player)
    Whether a controller sits in the player's slot.
    void
    Copies from into this state, replacing everything.
    boolean
    pressed(int player, GamepadButton button)
    Whether the player's controller has the button down right now.
    void
    setConnected(int player, boolean connected)
    Puts a controller into the player's slot, or takes it out.
    void
    setPressed(int player, GamepadButton button, boolean pressed)
    Sets one button of the player's controller.
    void
    setStick(int player, GamepadStick stick, double x, double y)
    Sets a stick of the player's controller; up is positive, as on the stage.
    void
    setTrigger(int player, GamepadTrigger trigger, double value)
    Sets a trigger of the player's controller, 0 (not at all) to 1 (fully).
    double
    stickX(int player, GamepadStick stick)
    The stick's x position, −1 (left) to 1 (right), 0 at rest.
    double
    stickY(int player, GamepadStick stick)
    The stick's y position, −1 (down) to 1 (up), 0 at rest.
    double
    trigger(int player, GamepadTrigger trigger)
    How far down the trigger is, 0 (not at all) to 1 (fully).

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PLAYERS

      public static final int PLAYERS
      The player slots, 1 to 4 in joystick-slot order.
      See Also:
  • Constructor Details

    • GamepadState

      public GamepadState()
      No controller connected, nothing pressed, sticks and triggers at rest.
  • Method Details

    • clear

      public void clear()
      Empties the whole state.
    • copyFrom

      public void copyFrom(GamepadState from)
      Copies from into this state, replacing everything.
    • connected

      public boolean connected(int player)
      Whether a controller sits in the player's slot.
    • setConnected

      public void setConnected(int player, boolean connected)
      Puts a controller into the player's slot, or takes it out.
    • pressed

      public boolean pressed(int player, GamepadButton button)
      Whether the player's controller has the button down right now.
    • setPressed

      public void setPressed(int player, GamepadButton button, boolean pressed)
      Sets one button of the player's controller.
    • stickX

      public double stickX(int player, GamepadStick stick)
      The stick's x position, −1 (left) to 1 (right), 0 at rest.
    • stickY

      public double stickY(int player, GamepadStick stick)
      The stick's y position, −1 (down) to 1 (up), 0 at rest.
    • setStick

      public void setStick(int player, GamepadStick stick, double x, double y)
      Sets a stick of the player's controller; up is positive, as on the stage.
    • trigger

      public double trigger(int player, GamepadTrigger trigger)
      How far down the trigger is, 0 (not at all) to 1 (fully).
    • setTrigger

      public void setTrigger(int player, GamepadTrigger trigger, double value)
      Sets a trigger of the player's controller, 0 (not at all) to 1 (fully).