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 void
drain()
Processes all events queued up, passing them to this object's InputProcessor.void
flush()
Empties the backing queue of data.boolean
getIgnoreInput()
Get the status for whether this should ignore input right now or not.com.badlogic.gdx.InputProcessor
getProcessor()
Gets this object's InputProcessor.boolean
hasNext()
Returns true if at least one event is queued.boolean
keyDown(int keycode)
boolean
keyTyped(char character)
boolean
keyUp(int keycode)
boolean
mouseMoved(int screenX, int screenY)
void
next()
Processes the first event queued up, passing it to this object's InputProcessor.boolean
scrolled(int amount)
void
setIgnoreInput(boolean ignoreInput)
Set the status for whether this should ignore input right now or not.void
setProcessor(com.badlogic.gdx.InputProcessor processor)
Sets the InputProcessor that this object will use to make sense of Key events.boolean
touchDown(int screenX, int screenY, int pointer, int button)
boolean
touchDragged(int screenX, int screenY, int pointer)
boolean
touchUp(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:
keyDown
in interfacecom.badlogic.gdx.InputProcessor
-
keyUp
- Specified by:
keyUp
in interfacecom.badlogic.gdx.InputProcessor
-
keyTyped
- Specified by:
keyTyped
in interfacecom.badlogic.gdx.InputProcessor
-
touchDown
- Specified by:
touchDown
in interfacecom.badlogic.gdx.InputProcessor
-
touchUp
- Specified by:
touchUp
in interfacecom.badlogic.gdx.InputProcessor
-
touchDragged
- Specified by:
touchDragged
in interfacecom.badlogic.gdx.InputProcessor
-
mouseMoved
- Specified by:
mouseMoved
in interfacecom.badlogic.gdx.InputProcessor
-
scrolled
- Specified by:
scrolled
in interfacecom.badlogic.gdx.InputProcessor
-