GMS 2 multiple animations per sprite strip

does any body know the best way to do virtual animations where I can specify what frames are in the animation and how fast it animates, but use a single sprite strip?

for example I might have this image

and I might have animations of it rolling left, rolling right, tilting left, tilting right, etc.
I don't want to make a bunch of sprites in game maker for something that could be done with a single strip.


Sure you can, you just have to define the start and end points of the animation and then manually set the image index to the start index and let it play out then when it reaches the end index go back to the start index and repeat.


I do this for my main character. I have a script called scrAnimator which looks like this:

isprite=argument0; //the name of the sprite to use
istart=argument1; //the first frame of the loop
iend=argument2; //the last frame of the loop
ispeed=argument3; //the speed of the loop
itype=argument4; //whether to loop the animation (0), freeze on the last frame (1), or end (2)


switch (itype)
case 0: //LOOP
if image_index>=iend || image_index<istart
case 1: //FREEZE ON LAST: I use this case for something like jumping, where after the 'launch sequence' the player stays on one frame (until he starts falling - a separate animation).
if image_index>iend || image_index<istart
if image_index=iend
case 2: //END: I use this case for things like shooting, where the player returns to an idle state at the end
if image_index>iend || image_index<istart
if image_index=iend
well that would be ok but its still limited what about frames that are not next to each other?

I was trying to make a script called animation_play(frames, frame, frame, frame..)
where it would play a animation based off of a array and timer but I had problems with it.

this is what I originally was doing
/// @description animation_create()
/// @frame..

var _array;
    _array[0] = 0; // the current frame
for (var i=1; i<argument_count-1; i++)
    _array[i] = argument[i]; //the actual frames
return _array;
/// @description animation_play()
/// @param framearray
/// @param delay
/// @param loop?

var _array = argument[0];
var _delay = argument[1];
var _loop  = argument[2];

alarm_set(255, -1);

if ((_array[0] == array_length_1d(_array) - 1) && (!_loop)) break;
alarm_set(255, _delay);

//This is a problem! It won't reach it inside a if staement.
//However it would require a delay parameter if I put it in another script. which would make it less dynamic.
if (alarm_get(255) <= 0)
    //I want to make it so it works without having to use object sprite_index's
    image_index = image_index + 1 mod image_number;
    if (!(_loop) && (image_index == image_number - 1)) break;
    alarm_set(255, _delay);
Last edited: