direction

This built in variable stores which direction an object is facing. It works like a good compass, it uses degrees, and 0 being the right, 180 being the left, 360 is the same direction as 0. As you can see, higher number, farther counter-clockwise. This can be used in many ways, for example trying to figure out which way to shoot the bullet.

 

Example #1:

//bullet create event

direction = player.direction;

speed = 1;

 

This is for changing the sprite to the right direction.  Note that for this to work your sprite that your using must be facing to the right (0 degrees).  Also note that image_angle is a registered only function.

 

This code would be put in the step event..

 

Example #2:

if keyboard_check(vk_right) then

{

direction -= 4;

}

if keyboard_check(vk_left)

{

direction += 4;

}

image_angle = direction;

 

direction will change by itself, you don't have to set a value.

 

Example #3:

//up press event

vspeed -= 1;

hspeed = 0;

 

If you now go to the draw event, and draw the direction variable onto the screen, it will change if you press up.  Here is a direction diagram. As you see, every 90 degrees is a right angle

 

 

direction

 

cityscape - Revision #1