Red Square
Treasure Hunt! I am going to demonstrate the RedSquare app today and you are going to make it. I shall leave you some breadcrumbs here.
setOnKeyPressed( (some lambda))
- You will need these two lines
so the canvas will respond to key events.canvas.setFocusTraversable(true); canvas.requestFocus();
- Look at
KeyCode
. - Look at
KeyEvent
- The red square is 50X50 (pixels)
- The canvas is 800 wide and 600 high
Here is the initial apperanace of the RedSquare app.
Here it is after the square has been moved by pressing the arrow keys. Each press in a given direction moves it 5 pixels.
Optional: Make it work for hjkl gamer keys too.