• 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 Code for using different Sprites depending of the Object direction

Y

Yoo

Guest
If I made it so that if I click the right key (or in my case 'D'), object will move to the right. While I'm holding the right key, object changes to the sprite that is animation for the movement to the right. Once I release the right key, the object stops moving, and transforms to the sprite that is idle animation for facing the right direction. And vice versa for the left side and the left key (in my case 'A').

I want to, besides WASD movement keys, and Space bar for jumping and similar, to use a mouse in my game. So that, once I click the left mouse button it does something... for now, just the animation (or the sprite). And the same for the right mouse click as well.

But how to do it, so that if I am facing right (or moving to the right), once I click the left mouse button I get the animation facing right, and again, vice versa for the left side.

If you want some more info, or to post some code, just say so.
 

GMWolf

aka fel666
I think the simples solutions short of using a ton of if else statements would be to have an array of sprites. e.g:
Code:
sprite_idle[0] = spr_idle_right;
sprite_idle[1] = spr_idle_up;
sprite_idle[2] = spr_idle_left;
sprite_idle[3] = spr_idle_down;
sprite_walk[0] = spr_walk_right;
REST OF THE SPRTIES
then store what direction you face whenever you move.
also keep track of what sprite you want to use. e.g
Code:
if keyboard_check(vk_left) {
 facing = 2;
 sprite = sprite_idle; //note, same name as the array
}
REST OF DIRECTIONS
and when drawing the sprite, use the varaible storing the array, and the facing variable:
Code:
draw_sprite(sprite[facing], 0, x, y); //change sprite_idle with whatever direction you are going.
 
Top