This is a simple method for moving in 8 directions, rather than the standard 4 (up, down, left and right). This is not the best method, but it is workable, using the keypad, which means that Numlock
must be on.
Knowledge Base
- Common Events
- Forks/Branch Conditions
- Variables
Variables
We'll only need one variable for the movement system,
0001:Dir Move.
Common Events
Open the Database (F9) and create a new Common Event,
8-Dir Movement and set the "Trigger" to "Parallel Process". This means that it will run in the background until one of the movement keys is pressed. Leave the "Switch" blank.
In the "Event Commands" section, place the following commands:
- First create a "Loop" (Tab 3), into which everything will be placed.
- Next, we'll need to define the "Key Input Processing" (Tab 3), which will be stored in our variable 0001:Dir Move. Make sure the "Wait Until Key Pressed" option is checked and only the "Number Keys 0-9 (10-19)" is checked as well.
- This is where things could become rather confusing, but it's not really that hard. Create 8 "Branch Conditions" with the "Else" option checked for each.
Set the first condition to "Variable 0001:Dir Move, Number Equal To 11 (the numerical value for 1, i.e. down/left).
Under the "Branch if" create a "Move Event" (Tab 2) and set the movement to down/left using the "Move Down/Left", setting the "Move Event" to "Hero" (usually selected by default).
Under the "Else Handler", repeat the process, but change the variable number and movement in the "Move Event" command to correspond with the direction (i.e. with the second fork, the "Variable" would be set to 12 and the direction to "Down", but ignoring number 15. Continue all the way up to 19. - Finally, in the last "Else Handler" insert a "Break Loop" command (Tab 3).
Complete Code
Notes
The downside to this method is that only the default movement keys (up, down, left and right) will repeat if they are held down. The other keys will need to be continuously pressed in order to move in that direction.