Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Sackboy on Sat 12/01/2013 14:54:47

Title: GUI movement without blocking (SOLVED)
Post by: Sackboy on Sat 12/01/2013 14:54:47
i want to create something like the floating numbers during a battle sequence of a rpg. for that i created a GUI with just one label on it. the label can display any random number. the GUI itself is only visible on certain events. if the GUI is visible the following should happen:

- GUI moves up steadily
- GUI slowly becomes more transparent

here is part of the code i use:

Code (AGS) Select
GUI.Visible=true;

int x=0;

while(x<50){

  GUI.Y=GUI.Y-5;
  GUI.Transparency=GUI.Transparency+2;

  x++;

  Wait(1);

}

GUI.Visible=false;


nothing fancy. the problem i have is that this function is blocking because of "Wait(1);". but if i run it without "Wait(1);" i don't see anything. it's like what happens in the while loop is not displayed.
i am searching for a way to make this code not blocking the game so that the player can still move while the GUI rises up and becomes more and more invisible. would be great if anyone could help me with that. thank you!
Title: Re: GUI movement without blocking
Post by: Khris on Sat 12/01/2013 15:30:13
What you would normally do is put a check inside the repeatedly_execute function and advance the GUI's state in there. This will change the GUI's appearance and position without blocking the game.
Basically, repeatedly_execute is an infinite while loop that runs during the entire game.

However, there's a module that does exactly what you want called Tween module (http://www.adventuregamestudio.co.uk/forums/index.php?topic=38015.0).
Using it, you can get the effect you want with a single line of code.
Title: Re: GUI movement without blocking
Post by: Sackboy on Sat 12/01/2013 20:01:56
wow, that was fast. thank you sir!  :)