GameMaker Using separate sprites for an animation

R.S.M.

Member
I'm not sure if there is a way to complete this. Essentially, I have 4 separate sprites, that I want cycled through at the press of a button. I've been searching everywhere, and the closest I've gotten is with this code.


/// CREATE EVENT
sprite_array = [sprCar00, sprCar01, sprCar02, sprCar03];

/// STEP EVENT or DRAW EVENT
sprite_index = sprite_array[ ( image_index % array_length_1d(sprite_array) ) ];

This only cycles certain images. There is probably a simple way to cycle separate images with a press of a button, but I'm at a complete loss.

Any ideas how to do this?
 

TheouAegis

Member
Animation end event:
if animate_array {
if ++frame == array_length_1d(sprite_array) {
animate_array = 0;
sprite_index = whatever;
}
else {
sprite_index = sprite_array[++frame]
image_index = 0;
}
}

Make a animate_array variable and a frame variable. Set frame to 0 and animate_array to 1 when you start the animation.
 
Top