Class GamepadState
java.lang.Object
org.openpatch.scratch.gamepad.GamepadState
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
FieldsModifier and TypeFieldDescriptionstatic final intThe player slots, 1 to 4 in joystick-slot order. -
Constructor Summary
ConstructorsConstructorDescriptionNo controller connected, nothing pressed, sticks and triggers at rest. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Empties the whole state.booleanconnected(int player) Whether a controller sits in the player's slot.voidcopyFrom(GamepadState from) Copiesfrominto this state, replacing everything.booleanpressed(int player, GamepadButton button) Whether the player's controller has the button down right now.voidsetConnected(int player, boolean connected) Puts a controller into the player's slot, or takes it out.voidsetPressed(int player, GamepadButton button, boolean pressed) Sets one button of the player's controller.voidsetStick(int player, GamepadStick stick, double x, double y) Sets a stick of the player's controller; up is positive, as on the stage.voidsetTrigger(int player, GamepadTrigger trigger, double value) Sets a trigger of the player's controller, 0 (not at all) to 1 (fully).doublestickX(int player, GamepadStick stick) The stick's x position, −1 (left) to 1 (right), 0 at rest.doublestickY(int player, GamepadStick stick) The stick's y position, −1 (down) to 1 (up), 0 at rest.doubletrigger(int player, GamepadTrigger trigger) How far down the trigger is, 0 (not at all) to 1 (fully).
-
Field Details
-
PLAYERS
public static final int PLAYERSThe 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
Copiesfrominto 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
Whether the player's controller has the button down right now. -
setPressed
Sets one button of the player's controller. -
stickX
The stick's x position, −1 (left) to 1 (right), 0 at rest. -
stickY
The stick's y position, −1 (down) to 1 (up), 0 at rest. -
setStick
Sets a stick of the player's controller; up is positive, as on the stage. -
trigger
How far down the trigger is, 0 (not at all) to 1 (fully). -
setTrigger
Sets a trigger of the player's controller, 0 (not at all) to 1 (fully).
-