• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Problem with image_angle [SOLVED]

S

Stac

Guest
Hi there.
My GMS version is 1.4 and I have a problem with next code:

Code:
key_right = keyboard_check(ord('D'));
key_left = -keyboard_check(ord('A'));
key_up = -keyboard_check(ord('W'));
key_down = keyboard_check(ord('S'));


hmove = key_left + key_right;
vmove = key_up + key_down;

hsp = hmove * movespeed;
vsp = vmove * movespeed;

x+=hsp;
y+=vsp;

if (key_left) image_angle = 180;
if (key_left == -1 && key_up == -1) image_angle = 135;
if (key_left == -1 && key_down == 1) image_angle = 225;
if (key_right) image_angle = 0;
if (key_right == 1 && key_up == -1) image_angle = 45;
if (key_right == 1 && key_down == 1) image_angle = 315;
if (key_up) image_angle = 90;
if (key_down) image_angle = 270;
The problem is that image_angle doesn't works, when I'm pressing "down and left" or "down and right".
And if I'm using next code(with "else"):

Code:
///Get the player's input

key_right = keyboard_check(ord('D'));
key_left = -keyboard_check(ord('A'));
key_up = -keyboard_check(ord('W'));
key_down = keyboard_check(ord('S'));

//React to inputs

hmove = key_left + key_right;
vmove = key_up + key_down;

hsp = hmove * movespeed;
vsp = vmove * movespeed;

x+=hsp;
y+=vsp;

if (key_left) image_angle = 180;
else if (key_left == -1 && key_up == -1) image_angle = 135;
else if (key_left == -1 && key_down == 1) image_angle = 225;
else if (key_right) image_angle = 0;
else if (key_right == 1 && key_up == -1) image_angle = 45;
else if (key_right == 1 && key_down == 1) image_angle = 315;
else if (key_up) image_angle = 90;
else if (key_down) image_angle = 270;
image_angle this time doesn't working, when I'm pressing "up and right" or "right and down".

I'm trying to fix it second day, but I'm newbie in GML so it's hard. Can you give me right working code or just advice how do it right (how bad my code)?

P.S. Sorry for mistakes in the text if they has. I'm came here, cuz don't have GM community in my country.
Thanks in advance.

GIF of second code working:
 
G

Gillen82

Guest
Try this:

Code:
if ( key_left && key_up ) { image_angle = 135; }
Just adjust for other angles.
 
T

TimothyAllen

Guest
Remove all that if else stuff and use point_direction
Code:
if (hmove != 0 || vmove != 0)
{
    image_angle = point_direction(0, 0, hmove, vmove);
}
 
S

Stac

Guest
Remove all that if else stuff and use point_direction
Code:
if (hmove != 0 || vmove != 0)
{
    image_angle = point_direction(0, 0, hmove, vmove);
}
Thanks for this. Really nice : D

Thank Gillen too
 
Last edited by a moderator:
Top