Game Development Reference
In-Depth Information
result in more optimal Thread usage! The resulting Java 8 lambda expression code
structure should look like the following, as shown in Figure 9-11 :
scene .setOnKeyPressed (KeyEvent event ) -> {
switch ( event .getCode()) {
case UP: up = true; break; // UP, DOWN,
LEFT, RIGHT constants from KeyCode class
case DOWN: down = true; break;
case LEFT: left = true; break;
case RIGHT: right = true; break;
}
});
Figure 9-11 . Convert the KeyEvent method to a lambda expression; notice that the event variable is used in the switch
Next, let's use a block copy and paste operation, and copy the .OnKeyPressed()
KeyEvent handing structure underneath itself, changing it to be an .OnKeyReleased
KeyEvent handling structure, with false values instead of true.
 
 
Search WWH ::




Custom Search