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

Way to change sprite?

N

NANI?

Guest
Lets say my object is connected to a sprite with an idle standing animation. When that object walks, I want it to switch to a sprite that is a walking animation. How dould I do this?
 
B

BubbleMage123

Guest
I don't know your variables, but I do know that for a plaformer, you could do this:
Code:
if(keyboard_check(vk_left) or keyboard_check(vk_right)){
    sprite_index = walking_sprite;
}
If you set those keyboard checks to a variable already, then you can just substitute.
 

Binsk

Member
Just to further explain the important piece of BubbleMage's code; sprite_index is what you want.

It is a built-in variable that exists for every object and it contains the current sprite id that that object is drawing. If you set the variable to a different sprite then the image that is drawn by that object will change.
 
G

gamedev4life

Guest
i made a GML tutorial on changing sprites for walking etc. you should also learn to make a finite state machine. fortunately i made tutorial videos for how to do these, they will help you very much!


 
Top