Package squidpony.squidgrid.gui.gdx
Class SquidKey
java.lang.Object
squidpony.squidgrid.gui.gdx.SquidKey
- All Implemented Interfaces:
com.badlogic.gdx.InputProcessor
public class SquidKey extends Object implements com.badlogic.gdx.InputProcessor
This wraps an InputProcessor, storing all key events and allowing them to be processed one at a time using next() or
all at once using drain(). To have an effect, it needs to be registered by calling Input.setInputProcessor(SquidKey).
It does not perform the blocking functionality of the now-removed Swing SquidKey implementation, because this is meant to run in an event-driven libGDX game and should not step on the toes of libGDX's input handling. To block game logic until an event has been received, check hasNext() in the game's render() method and effectively "block" by not running game logic if hasNext() returns false. You can get an event if hasNext() returns true by calling next().
It does not perform the blocking functionality of the now-removed Swing SquidKey implementation, because this is meant to run in an event-driven libGDX game and should not step on the toes of libGDX's input handling. To block game logic until an event has been received, check hasNext() in the game's render() method and effectively "block" by not running game logic if hasNext() returns false. You can get an event if hasNext() returns true by calling next().
- Author:
- Eben Howard - http://squidpony.com - howard@squidpony.com, Nathan Sweet, Tommy Ettinger
-
Constructor Summary
Constructors Constructor Description SquidKey()Constructs a SquidKey with no InputProcessor; for this to do anything, setProcessor() must be called.SquidKey(com.badlogic.gdx.InputProcessor processor)Constructs a SquidKey with the given InputProcessor.SquidKey(com.badlogic.gdx.InputProcessor processor, boolean ignoreInput)Constructs a SquidKey with the given InputProcessor. -
Method Summary
Modifier and Type Method Description voiddrain()Processes all events queued up, passing them to this object's InputProcessor.voidflush()Empties the backing queue of data.booleangetIgnoreInput()Get the status for whether this should ignore input right now or not.com.badlogic.gdx.InputProcessorgetProcessor()Gets this object's InputProcessor.booleanhasNext()Returns true if at least one event is queued.booleankeyDown(int keycode)booleankeyTyped(char character)booleankeyUp(int keycode)booleanmouseMoved(int screenX, int screenY)voidnext()Processes the first event queued up, passing it to this object's InputProcessor.booleanscrolled(int amount)voidsetIgnoreInput(boolean ignoreInput)Set the status for whether this should ignore input right now or not.voidsetProcessor(com.badlogic.gdx.InputProcessor processor)Sets the InputProcessor that this object will use to make sense of Key events.booleantouchDown(int screenX, int screenY, int pointer, int button)booleantouchDragged(int screenX, int screenY, int pointer)booleantouchUp(int screenX, int screenY, int pointer, int button)
-
Constructor Details
-
SquidKey
public SquidKey()Constructs a SquidKey with no InputProcessor; for this to do anything, setProcessor() must be called. -
SquidKey
Constructs a SquidKey with the given InputProcessor.- Parameters:
processor- An InputProcessor that will handle keyDown(), keyUp(), and keyTyped() events
-
SquidKey
Constructs a SquidKey with the given InputProcessor.- Parameters:
processor- An InputProcessor that will handle keyDown(), keyUp(), and keyTyped() eventsignoreInput- the starting value for the ignore status; true to ignore input, false to process it.
-
-
Method Details
-
setProcessor
Sets the InputProcessor that this object will use to make sense of Key events.- Parameters:
processor- An InputProcessor that will handle keyDown(), keyUp(), and keyTyped() events
-
getProcessor
Gets this object's InputProcessor.- Returns:
- this object's InputProcessor
-
getIgnoreInput
Get the status for whether this should ignore input right now or not. True means this object will ignore and not queue keypresses, false means it should process them normally. Useful to pause processing or delegate it to another object temporarily.- Returns:
- true if this object currently ignores input, false otherwise.
-
setIgnoreInput
Set the status for whether this should ignore input right now or not. True means this object will ignore and not queue keypresses, false means it should process them normally. Useful to pause processing or delegate it to another object temporarily.- Parameters:
ignoreInput- true if this should object should ignore and not queue input, false otherwise.
-
drain
Processes all events queued up, passing them to this object's InputProcessor. -
hasNext
Returns true if at least one event is queued.- Returns:
- true if there is an event queued, false otherwise.
-
next
Processes the first event queued up, passing it to this object's InputProcessor. -
flush
Empties the backing queue of data. -
keyDown
- Specified by:
keyDownin interfacecom.badlogic.gdx.InputProcessor
-
keyUp
- Specified by:
keyUpin interfacecom.badlogic.gdx.InputProcessor
-
keyTyped
- Specified by:
keyTypedin interfacecom.badlogic.gdx.InputProcessor
-
touchDown
- Specified by:
touchDownin interfacecom.badlogic.gdx.InputProcessor
-
touchUp
- Specified by:
touchUpin interfacecom.badlogic.gdx.InputProcessor
-
touchDragged
- Specified by:
touchDraggedin interfacecom.badlogic.gdx.InputProcessor
-
mouseMoved
- Specified by:
mouseMovedin interfacecom.badlogic.gdx.InputProcessor
-
scrolled
- Specified by:
scrolledin interfacecom.badlogic.gdx.InputProcessor
-