How to code random play of sprite animation [Solved]

Started by subspark, Sun 08/11/2009 12:03:51

Previous topic - Next topic

subspark

Hey folks. I'm trying to create a repeating random timer that runs the following code anywhere between 45 to 70 seconds each time.
Code: ags
oIdol.SetView(IDOL_SPARKLE, 0, 0);
oIdol.Animate(0, 1, eOnce, eNoBlock);


I must admit I'm a little clueless on how to approach this.

Cheers,
Sparky.

NsMn

To get a random value between two values, use, e.g.:
Code: ags
Random(10)+10;


This will return a value between 10 and 20.

subspark

#2
Thanks, I already know that. However I have no clue how to incorporate a timer into this which activates the animation of my sprite. I've explained it better above.

Cheers,
Sparky.

NsMn

Code: ags

function repeatedly_execute(){
 if(IsTimerExpired(10)==1 && oIdol.Animating==false){
   oIdol.SetView(IDOL_SPARKLE, 0, 0);
   oIdol.Animate(0, 1, eOnce, eNoBlock);
   SetTimer(10,0);
 }
 if(IsTimerExpired(10)==0 && oIdol.Animating==false)SetTimer(10,Random(25)+45);
}


Khris

This should suffice:

Code: ags
function repeatedly_execute() {
  if (IsTimerExpired(10)) {
    oIdol.SetView(IDOL_SPARKLE, 0, 0);
    oIdol.Animate(0, 1, eOnce, eNoBlock);
    SetTimer(10,Random(25)+45)
  }
}


To start the sequence, set the timer in after_fadein.

subspark

Thanks guys, You rock!  8)

Cheers,
Sparky.

SMF spam blocked by CleanTalk