Update a series of sprites with a non-blocking delay

Started by Knox, Wed 02/06/2010 21:09:02

Previous topic - Next topic

Knox

I found this thread about the problem Im trying to solve, and I was wondering if there was any other way, or is this the best way to "replace" Wait() so its non-blocking?

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=40783.0

What Im doing is when a player receives damage, the health goes down and I display this change by changing the health bar sprite. Im making the bar go down in increments of 1, so say you lose 5 points, it goes down by 1 bar, 5 times...I decided to use Wait(5), seems to be the nicest wait time between sprite changes. The only down-side to this is that wait blocks, and I see my wait cursor flicker cause its constantly waiting and chaning sprites while in the function's loop. I could just render the cursor invisible duing the short Wait(5), but it would be even better to get around this another way all together.

So what Im asking is...what would some other options be (if any)?

--All that is necessary for evil to triumph is for good men to do nothing.

Vince Twelve

You can use a counter to count down and the repeatedly_execute_always to change the bar.
Code: ags

int barDisplayCounter=5; //declare and initialize counter outside of functions

function repeatedly_execute_always(){ 
  if(barDisplayCounter==0){
    if(some expression that decides if the bar needs changing){
      change the bar by one
    }
    barDisplayCounter=5; //reset the counter
  }
  else{
    barDisplayCounter--; //count down
  }

}


Rep ex always is your friend when you want to manually do non-blocking things. 

Knox

Hey thanks! This post combined with extra help from Ryan got the job done :)
--All that is necessary for evil to triumph is for good men to do nothing.


SMF spam blocked by CleanTalk