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?
current_image = 0;
myList = ds_list_create();
ds_list_add(myList, 0, 3, 5, 8, 17);
current_image+=1;
if( current_image >= ds_list_size(myList) ){
current_image = 0;
}
draw_sprite( sprite_index, myList[| current_image], x, y);
current_image+=numberSmallerThanOne;
if( current_image >= ds_list_size(myList) ){
current_image = 0;
}
draw_sprite( sprite_index, myList[| floor(current_image)], x, y);
That makes sense! Thank you!!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:
You could now do something like this in the Draw event:Code:current_image = 0; myList = ds_list_create(); ds_list_add(myList, 0, 3, 5, 8, 17);
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.Code:current_image+=1; if( current_image >= ds_list_size(myList) ){ current_image = 0; } draw_sprite( sprite_index, myList[| current_image], x, y);
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:
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.Code:current_image+=numberSmallerThanOne; if( current_image >= ds_list_size(myList) ){ current_image = 0; } draw_sprite( sprite_index, myList[| floor(current_image)], x, y);