Game Development Reference
In-Depth Information
scene.
setOnKeyPressed
(KeyEvent event) -> {
switch (event.getCode()) {
case UP: up = true; break;
case DOWN: down = true; break;
case LEFT: left = true; break;
case RIGHT: right = true; break;
case W:
wKey
= true; break;
case S:
sKey
= true; break;
case A:
aKey
= true; break;
case D:
dKey
= true; break;
}
});
scene.
setOnKeyReleased
(KeyEvent event) -> {
switch (event.getCode()) {
case UP: up = true; break;
case DOWN: down = true; break;
case LEFT: left = true; break;
case RIGHT: right = true; break;
case W:
wKey
= true; break;
case S:
sKey
= true; break;
case A:
aKey
= true; break;
case D:
dKey
= true; break;
}
});
As you can see in
Figure 13-14
, the code is error-free, because I added wKey, sKey,
aKey, and dKey variables to the Boolean up, down, left, right compound declaration
statement located at the top of the InvinciBagel.java class.