• 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!

(Solved!) How to start an animated sprite from a random number?

Hi Folks,

I try to make a sprite-animation, starting from a random number.
But I wasn´t successful. I have a walking zombie, spawning in a level
up to 6 instances, maximum. The sprite has 32 images. Now I just
want for each added zombie a new randomized number, where the
its animation has to start, and then repeating (random number just
at the beginning).

Hope I could explain it well!?
greetings, Archie.
 

woods

Member
couldnt you do something like this..


obj_zombie create event
Code:
image_speed = 1;
image_index = irandom(0,32);

or set a variable in the spawner step event to pick a random number and use irandom()
 

JasonTomLee

Member
You could set the index based on the max number of 'sprite indexes' and then irandomize it to the nearest whole number. You subtract 1 because sprite_index starts at 0, not 1

image_index = irandom( image_number-1 );
 
Hi Woods.

So simple! I just set one number (maximum image number of sprite) into the brackets of irandom. Works! Thank you for your help! :)

Best wishes.
Archibaldo.
 
Top