Friday, 11 April 2014

GameMaker - Simple Player Movements Coding (Windows)

Coding GML is simple, but can be in such depth when you're creating a game with many sprites and objects. Obviously the first thing you need to know about coding is the player movements. Most beginners generally use the drag and drop variables to create movements, however, I find it easier to use simple coding (GML) and I'm going to share with you how I do it.

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.


No comments:

Post a Comment