|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectJTP.KeyHandler
public class KeyHandler
Class for handling keyboard control in-game.
Field Summary | |
---|---|
static int |
GAME_1P
Handling mode: Only Player 1 keys allowed |
static int |
GAME_2P
Handling mode: Both Player keys allowed |
static int |
NORMAL
Handling mode: Bypassed (handling performed by Screen class) |
Constructor Summary | |
---|---|
KeyHandler(Screen s)
Constructs a new instance of KeyHandler . |
Method Summary | |
---|---|
void |
autoStart()
To be called at start of level (to perform automatic moves, if any) |
void |
enableSpaceKey()
To be called when a popup message is shown in-game so it can be cancelled via keyboard. |
boolean |
keyDown()
Used by Screen class to determine whether a key is being
held down in-game. |
void |
keyPressed(KeyEvent e)
Handles key-down events. |
void |
keyReleased(KeyEvent e)
Handles key-up events. |
void |
keyTyped(KeyEvent e)
Handles key-typed events. |
void |
reset()
Resets state of this KeyHandler instance. |
void |
setMode(int mode,
boolean repeatsAllowed)
Sets key input handling mode. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NORMAL
Screen
class)
public static final int GAME_1P
public static final int GAME_2P
Constructor Detail |
---|
public KeyHandler(Screen s)
KeyHandler
.
s
- the parent processing class.Method Detail |
---|
public void setMode(int mode, boolean repeatsAllowed) throws IllegalArgumentException
mode
- the mode to use. Available modes:
NORMAL
- Simply forwards all events to the
Screen
classGAME_1P
- Handling of 1st player keys onlyGAME_2P
- Handling of both players' keysrepeatsAllowed
- indicates whether holding down a key should produce
multiple events or not. Note: This parameter has no effect in NORMAL
mode.
IllegalArgumentException
- if mode
is not one of
NORMAL
, GAME_1P
or GAME_2P
.public void reset()
KeyHandler
instance.
Note: The repeatsAllowed
flag is not reset.
public void autoStart()
public void enableSpaceKey()
public void keyPressed(KeyEvent e)
keyPressed
in interface KeyListener
e
- the incoming keyboard event.public void keyReleased(KeyEvent e)
keyReleased
in interface KeyListener
e
- the incoming keyboard event.public boolean keyDown()
Screen
class to determine whether a key is being
held down in-game.
true
is a player or control key is in the down state,
given the current key handling mode. Note: In NORMAL
mode
this will always return false
.public void keyTyped(KeyEvent e)
Scene
class because it is only used when entering characters as part of a new
highscore.
keyTyped
in interface KeyListener
e
- the incoming keyboard event.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |