• 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 Filter out image_indexes within an object

C

CinnaBrynn

Guest
So, i'm creating a list that contains 5 image_indexes of an object's sprite_index so I can filter them out from the rest. Is there a way to do that within an object?
 
C

CinnaBrynn

Guest
The sprite that is attached to the object has 28 images. I have written code that allows me to choose up to 5 images of my choice to put into a ds_list. My issue is, how do I only display the 5 images that I chose from the list.
 

Tsa05

Member
Instead of having the object draw itself, you'll want to draw with code, and keep track of image_index yourself.
Suppose you have this in the Create event:

Code:
current_image = 0;

myList = ds_list_create();
ds_list_add(myList, 0, 3, 5, 8, 17);
You could now do something like this in the Draw event:
Code:
current_image+=1;
if( current_image >= ds_list_size(myList) ){
     current_image = 0;
}

draw_sprite( sprite_index, myList[| current_image], x, y);
That code loops from zero up to the size of the list, and uses the numbers in the list as the sub images to draw.

Of course, this will cause the animation to play 1 frame per step, too. If you want it slower, you'll have to accommodate for speed, too. Simple method:
Code:
current_image+=numberSmallerThanOne;
if( current_image >= ds_list_size(myList) ){
     current_image = 0;
}

draw_sprite( sprite_index, myList[| floor(current_image)], x, y);
I've incremented the current image by a fractional amount, so it takes more than one step to go up by 1.... and then used the floor() function to round it off when drawing.
 
C

CinnaBrynn

Guest
Instead of having the object draw itself, you'll want to draw with code, and keep track of image_index yourself.
Suppose you have this in the Create event:

Code:
current_image = 0;

myList = ds_list_create();
ds_list_add(myList, 0, 3, 5, 8, 17);
You could now do something like this in the Draw event:
Code:
current_image+=1;
if( current_image >= ds_list_size(myList) ){
     current_image = 0;
}

draw_sprite( sprite_index, myList[| current_image], x, y);
That code loops from zero up to the size of the list, and uses the numbers in the list as the sub images to draw.

Of course, this will cause the animation to play 1 frame per step, too. If you want it slower, you'll have to accommodate for speed, too. Simple method:
Code:
current_image+=numberSmallerThanOne;
if( current_image >= ds_list_size(myList) ){
     current_image = 0;
}

draw_sprite( sprite_index, myList[| floor(current_image)], x, y);
I've incremented the current image by a fractional amount, so it takes more than one step to go up by 1.... and then used the floor() function to round it off when drawing.
That makes sense! Thank you!!
 
Top