This page will show how to create top-down movement step-by-step. Let’s get started!
The first step is to create a player object. In the create event you will need a few variables.
move_speed = 2; move_x = 0; move_y = 0;
In the step event we can do the following:
The keyboard_check function returns either true or false, which is equal to 0 or 1. This means that we can actually calculate the net input in one line for each axis. If D is pressed and A is not, the result equals 1 – 0, which results in 1. If A is pressed and D isn’t the result will be -1. We can apply this same principle to the Y axis.
After that we can set move_x and move_y to equal the input multiplied by the move speed, this will result in the player moving either horizontally, vertically or diagonally (if both input_x and input_y are not 0).
To finalize simply do the following:
x += move_x;
y += move_y;
if no buttons are pressed the player will not move as move_x and move_y will be equal to zero.
That’s it, you should have simple top-down movement going on now!