It's actually quite simple as Game Maker handles most of the animating for you.
Create one sprite for each of your actions: have one sprite containing all the frames of your walk cycle, one for the jumping animation, one for the talking loop and so on. You can tell your game object to use that sprite by assigning its
sprite_index variable to it. The animation will loop at the same speed as your room's speed by default, but you can change that by setting the
image_speed variable to a different value. (e.g.:"image_speed = 0;" displays a static frame, whereas "image_speed = 0.5;" displays your animation at
half the room speed)
Say you have named your walking and standing sprites
spr_walk and
spr_idle respectively. Your code could look slightly like this:
if (keypress) { //Started walking
[...] //actually move
sprite_index = spr_walk; //Set the correct sprite (walking animation)
image_speed = 1/4; //Room speed is 4 times faster than animation. (In a 60 fps game, the animation would show 15 frames per second.)
}
if (keyrelease) { //Stopped walking
sprite_index = spr_idle;
image_speed = 0;
}
Additionally, you can control your animation's current frame with the
image_index variable. Might be useful if you want to do something when an object with an animated sprite hits a certain frame. You do not need to manually increment this variable if you set the image_speed correctly.
I hope this helped. If you have any other questions, ask away!
