• 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!

GameMaker Mirror a sprite

M

Mallard8

Guest
Hi again,
I have a sprite that faces and walks right using (vk_right)
Do I need to create another sprite to walk and face left or can I just mirror the same sprite?


That was the original question before I had a think about it and looked at the Help section.
Now the question is this, I can get the sprite to mirror using this code

if (keyboard_check(vk_right)) x += 4 image_xscale = 1; // Sprite walk and face Right
if (keyboard_check(vk_left)) x -= 4 image_xscale = - 1; // Sprite walk and face Left

Sprite faces left before I even hit a key and doesn't mirror back right no matter what I try
ie:
image_xscale = 0
image_xscale = 1
image_xscale = +1
Or having just
if (keyboard_check(vk_right)) x += 4
 

Perseus

Not Medusa
Forum Staff
Moderator
If you have more than one action due to be executed after the if statement evaluation, they need to be placed inside curly brackets as demonstrated below:
Code:
if (keyboard_check(vk_right)) {
    x += 4;
    image_xscale = 1;
} else if (keyboard_check(vk_left)) {
    x -= 4;
    image_xscale = -1;
}
 
M

Mallard8

Guest
Thanks for the example code and clear explanation another lesson learnt.
 
Top