First of you'll want to open GameMaker and start a new project or open the one you want to create player movements for. Then double click on the player, from here you need to add a 'Step Event' (just a normal step event will do). Drag in from the 'Control Tab' the 'Execute Code' icon; when this has opened, type the following code:
![]() |
The coding above shows you how to create left and right movements via the arrow keys on the keyboard. |
Normally, when you create a game you have two separate sprites for each direction you move. So when you change from going in the right direction you need to change the sprite to look the other way. To do this, all you need to do is copy the code you've just typed and paste it in a separate line BUT at the end of this, add the following:
![]() |
As you can see, I've added sprite_index = SPRITE NAME to the end of the movement code because this changes the sprite when the movement key is pressed. |