GMS 2 Having trouble with sprites facing directions.

B

BlueBird02

Guest
My character stops in the correct direction where the key is supposed to be (turning Right and stops where it suppose to look)

But when I turn left and stop, it just turns the opposite where it supposes to go.

look at the gif to for better understanding.TUNI.gif
 

Slyddar

Member
When requesting help it's always easier to get help if you post your code, otherwise we're all guessing at what you've done.

At a guess you are setting the image_xscale, or a dir/facing variable each step. Before setting this you need to have a check and only set it if the character is actually moving.
 
B

BlueBird02

Guest
When requesting help it's always easier to get help if you post your code, otherwise we're all guessing at what you've done.

At a guess you are setting the image_xscale, or a dir/facing variable each step. Before setting this you need to have a check and only set it if the character is actually moving.
here's the code

if (keyboard_check(ord("D"))) {
x += walkspeed;
image_speed = walkspeed / 1;
sprite_index = spr_walkpain
}
if (keyboard_check(ord("A"))) {
x -= walkspeed;
image_speed = walkspeed / 1;
sprite_index = spr_walkleftpain
}
if (keyboard_check(vk_nokey)) {
image_speed = 1;
sprite_index = spr_lillystandright
}
 

ancientarts

Member
if both animations are the same left or right you can just invert the width to flip the image.

your spr_lillystandright im assuming is drawn to face right. simply need to know the current direction lilly is facing.

current_dir = 1; in ord"d" and current_dir = -1; in ord"A"
if (current_dir = 1) {sprite_xscale = 1;}
if (current_dir = -1) {sprite_xscale = -1;}

i mean there are easier ways.
start here :
 
B

BlueBird02

Guest
Isn't this just a duplicate of the thread where you have asked exactly the same question and I have provided a possible answer to you?
Yeah, it was a big mistake. I was still trying to get used to posting threads in the forums. I tried deleting that thread when I accidentally picked the wrong forum but couldn't figure it out, the thread hasn't moved to a different forum so I thought I have to try again and post it in the right forum section. But it did, now I can't delete the thread cause I don't know how to.
 
Yeah, it was a big mistake. I was still trying to get used to posting threads in the forums. I tried deleting that thread when I accidentally picked the wrong forum but couldn't figure it out, the thread hasn't moved to a different forum so I thought I have to try again and post it in the right forum section. But it did, now I can't delete the thread cause I don't know how to.
You cannot delete threads. Moderators have full control over all posts. You could report it and ask for it to be moved, closed, or perhaps the best thing would be to have both topic merged. Otherwise it is just getting confusing as to what you have tried, and what multiple people are helping you with across two separate topics. :)
 
B

BlueBird02

Guest
You cannot delete threads. Moderators have full control over all posts. You could report it and ask for it to be moved, closed, or perhaps the best thing would be to have both topic merged. Otherwise it is just getting confusing as to what you have tried, and what multiple people are helping you with across two separate topics. :)
Thank you.

anyway, I think I'm able to fix it. Hold on.
 
B

BlueBird02

Guest
You cannot delete threads. Moderators have full control over all posts. You could report it and ask for it to be moved, closed, or perhaps the best thing would be to have both topic merged. Otherwise it is just getting confusing as to what you have tried, and what multiple people are helping you with across two separate topics. :)
anyway, I fix up the code you made mistakes.

if (keyboard_check(ord("D"))) {
x += walkspeed;
image_speed = walkspeed / 1;
sprite_index = spr_walkpain
}
if (keyboard_check(ord("A"))) {
x -= walkspeed;
image_speed = walkspeed / 1;
sprite_index = spr_walkleftpain
}
if (keyboard_check(vk_nokey)) {
image_speed = 1;
if (sprite_index == spr_walkpain) {
sprite_index = spr_lillystandright;
} else {
sprite_index = spr_lillystandleft;
}
}
 
B

BlueBird02

Guest
if both animations are the same left or right you can just invert the width to flip the image.

your spr_lillystandright im assuming is drawn to face right. simply need to know the current direction lilly is facing.

current_dir = 1; in ord"d" and current_dir = -1; in ord"A"
if (current_dir = 1) {sprite_xscale = 1;}
if (current_dir = -1) {sprite_xscale = -1;}

I mean there are easier ways.
start here :
Wait. I think your on to something...

where do I put the code?

if (keyboard_check(ord("D"))) {
x += walkspeed;
image_speed = walkspeed / 1;
sprite_index = spr_walkpain
}
if (keyboard_check(ord("A"))) {
x -= walkspeed;
image_speed = walkspeed / 1;
sprite_index = spr_walkleftpain
}
if (keyboard_check(vk_nokey)) {
image_speed = 1;
if (sprite_index == spr_walkpain) {
sprite_index = spr_lillystandright;
} else {
sprite_index = spr_lillystandleft;
}
}
 

Slyddar

Member
Like the suggestion above by ancientarts, there are easier ways to do what you are trying to do. That video series by Shaun Spalding is very good and a great start. You will save yourself many hours of pain by watching how others have achieved what you are trying to create.

In answer to your question, the code above should go in the players step event.

image_speed = walkspeed / 1;
Also worth noting dividing anything by 1 will result in the same number.
 

ancientarts

Member
ok ill give an answer this once
Code:
    key_left = keyboard_check(ord("A"));
    key_right = keyboard_check(ord("D"));

    var move = key_right - key_left;                            
    hsp = move * walksp;

       current_dir = sign(hsp);
       x = x + hsp;

      if (key_right) || (key_left)
      {
             sprite_index = spr_walking;
      } else if (hsp == 0)
      {
             sprite_index = spr_idle;
      }

      if (current_dir == 1)
      {
               sprite_xscale = 1;
      } else if (current_dir == -1)
      {
               sprite_xscale = -1;
      }
 
Last edited:
B

BlueBird02

Guest
ok ill give an answer this once
Code:
    key_left = keyboard_check(ord("A"));
    key_right = keyboard_check(ord("D"));

    var move = key_right - key_left;                           
    hsp = move * walksp;

       current_dir = sign(hsp);
       x = x + hsp;

      if (key_right) || (key_left)
      {
             sprite_index = spr_walking;
      } else if (hsp == 0)
      {
             sprite_index = spr_idle;
      }

      if (current_dir == 1)
      {
               sprite_xscale = 1;
      } else if (current_dir == -1)
      {
               sprite_xscale = -1;
      }
Thank you.
 
Top