Next, click on "obj_player" in the resource tree and drag it out to the center of the room.
Double click on "rm_world_map" to open the room editor. If an object is the blueprint for a house, an instance is the actual house.
Next we'll need to insert an instance of our player into the room. This is the first frame of animation for our sprite, which in our case is the normal standing position. Finally, if we weren't moving in any direction we set "image_index" to 0. "image_speed" is another special property of an object that determines how fast we cycle through the frames of our sprite animation. sprite_index is also a special variable in an object that allows us to assign which sprite is associated to an object. We also set "sprite_index" equal to our player_direction. x and y are special variables in an object that correlate to the object's position inside the room, so by setting this x and y values we are actually moving our object around the screen.
If so, we take "x" and set it equal to our current x value plus the value we determined for our movement speed along the x axis. That gives us the ability to reduce the values of our x and y positions without needing to have a positive and negative movement speed.įollowing that, we check to see if our x_axis or y_axis variables are anything other than 0. You'll notice that to move left or up we actually take our movement speed and multiple it by -1. The next set of "else if" statements do the same thing for the left, up and down arrow keys, setting our movement speed along the x or y axis as appropriate. "keyboard_check(vk_right)" will return true if the right arrow key is currently pressed, so we'd go ahead and set our movement along the x axis to be equal to the movement speed, and set the player direction to be equal to the macro "RIGHT", meaning right now we want to use the sprite "spr_player_right". This checks the current state of our keyboard to see if the right arrow key is being pressed. Next we used the function "keyboard_check" to check for "vk_right". The first two lines set our default movement to 0.