Controlling a sprite with the keyboard
Let's add some game logic to the game. Double-click on the screen in the first layout and add the keyboard and mouse objects, as shown in the following screenshot. This allows us to use the Keyboard and the Mouse in our game.
Let's set up the game logic:
- We need to make the player move with the WASD control and rotate to the mouse location. Click on the player and add the behavior.
- Once you see this dialog box, click on the plus sign to add a behavior.
- Scroll down and add the 8Direction behavior:
- Once you have added the 8Direction behavior, it should appear just like the preceding screenshot. Exit this window and go to the layout.
What we want is for the player to use either the arrow keys or the WASD controls to move around. It's good to have both, as players have different preferences. The following are the steps to do so:
- First, we have to change the eight directions to four. You can have a game with the full eight directions, but four is...