SOLVED The character disappears.

U

uni00

Guest
Character disappears when no keyboard is pressed
This is the only code for that player.
thanks!

GML:
--o_player1.step--
left = (keyboard_check(vk_left));
right = (keyboard_check(vk_right));
up = (keyboard_check(vk_up));
down = (keyboard_check(vk_down));

hspeed = (right - left);
vspeed = (down - up);

image_xscale = (right - left) * 0.4;
 
U

uni00

Guest
Character disappears when no keyboard is pressed
This is the only code for that player.
Probably image_xscale() is the problem, but I'm not sure what to do.
thanks!

GML:
--o_player1.step--
left = (keyboard_check(vk_left));
right = (keyboard_check(vk_right));
up = (keyboard_check(vk_up));
down = (keyboard_check(vk_down));

hspeed = (right - left);
vspeed = (down - up);

image_xscale = (right - left) * 0.4;
 

Mk.2

Member
That's my bad, I'll correct the code I gave you. :p image_xscale is being set to 0 if both right and left are pressed, or neither are pressed.

GML:
--o_player1.step--
left = (keyboard_check(vk_left));
right = (keyboard_check(vk_right));
up = (keyboard_check(vk_up));
down = (keyboard_check(vk_down));

hspeed = (right - left);
vspeed = (down - up);

if (sign(hspeed) != 0) image_xscale = sign(hspeed) * 0.4; //Only change the x scale if right or left is being held
else image_xscale = 1; //If both or neither are being held, set the x scale back to 1
 
U

uni00

Guest
That's my bad, I'll correct the code I gave you. :p image_xscale is being set to 0 if both right and left are pressed, or neither are pressed.

GML:
--o_player1.step--
left = (keyboard_check(vk_left));
right = (keyboard_check(vk_right));
up = (keyboard_check(vk_up));
down = (keyboard_check(vk_down));

hspeed = (right - left);
vspeed = (down - up);

if (sign(hspeed) != 0) image_xscale = sign(hspeed) * 0.4; //Only change the x scale if right or left is being held
else image_xscale = 1; //If both or neither are being held, set the x scale back to 1
That's not true. Please do not apologize. Thank you for taking the time to answer me.
 

Mk.2

Member
That's not true. Please do not apologize. Thank you for taking the time to answer me.
No problem. It was the code I originally gave you that was the problem, but I've since edited it to the correct version in the other thread.
 

Yal

šŸ§ *penguin noises*
GMC Elder
image_xscale = (right - left) * 0.4;
if right and left are equal, you set image_xscale to zero... which makes the object disappear because it's now zero pixels wide. This will happen both if you press no key, or both at once.
 
Top