Keep showing the mouse cursor on FadeIn and FadeOut

Started by Gal Shemesh, Thu 03/08/2023 13:02:54

Previous topic - Next topic

Gal Shemesh

Following the custom 'FadeIn' and 'FadeOut' route I went with - is there any way to make it run in a non-blocking behavior? I mean, when changing the transparancy in a 'while' loop we must use 'Wait(1)' for the least, so I guess this is what makes function a blocking one. Yet, I'm willing to play the custom fade while animations are running simultaneously.

I tried putting the .Animate function before the custom fade with eNoBlock, but I'm not sure if it's the right way to doing it, and besides I do wish to have the animations that plays during the fade to be with eBlock, like when a walk-in animation of the player is playing when he enters the room.

Another thing I'm trying to figure out is if I could make my custom FadeIn and FadeOut to play automatically upon changing rooms and entering rooms, so I won't need to copy and paste the code for every room.

Thanks

Gal Shemesh,
goldeng

RootBound

#21
Not sure how to do the fade non blocking except maybe using the tween module's tween transparency command. That's probably the easiest.

For not having to copy and paste the code, you could put the custom fadein and fadeout functions in the global script and then export the functions so that you can call them from any room.

If you're using a GUI for the black screen it should work fine. If you are using a room object for the black screen you probably would need to use a global object pointer (I think that's an option) instead of referring directly to the in room object. Then you define the global object pointer in each room as referring to the room object you're using.

(Hopefully I am not out of my depth here as I am away from the computer and unable to test this method. It will result in a null pointer error if the function is called before the pointer is defined. There might be other pitfalls I'm not thinking of too).

The change room command would stay in the room script, after the fadeout.
J. They/them. Here are my most recent games:

Crimson Wizard

#22
Quote from: Gal Shemesh on Mon 07/08/2023 12:55:10Following the custom 'FadeIn' and 'FadeOut' route I went with - is there any way to make it run in a non-blocking behavior? I mean, when changing the transparancy in a 'while' loop we must use 'Wait(1)' for the least, so I guess this is what makes function a blocking one. Yet, I'm willing to play the custom fade while animations are running simultaneously.

I tried putting the .Animate function before the custom fade with eNoBlock, but I'm not sure if it's the right way to doing it, and besides I do wish to have the animations that plays during the fade to be with eBlock, like when a walk-in animation of the player is playing when he enters the room.

This may be a right way of doing this, and that will also prevent player from any interaction, as player input is ignored during Wait calls.

If your meaning is to play a sequence of actions in parallel to your fade effect, then you would have to implement  a cutscene/sequence state check in repeatedly_execute_always. This may go two ways:
1) play fade effect in a loop with Wait(1) inside, while running & checking for other actions in rep-exec-always
2) script fade effect in rep-exec-always without Wait, advancing its transparency step-by-step with every rep-exec call. This will allow to trigger it, and then play any sequence of blocking actions, while the Fade effect is running in "background".

Tween module runs its actions in rep-exec (or rep-exec-always, I don't remember which one, or if there's a way to select).
Indeed, using Tween module is easiest for this purpose, and it may simplify many other things in your game too.


Quote from: Gal Shemesh on Mon 07/08/2023 12:55:10Another thing I'm trying to figure out is if I could make my custom FadeIn and FadeOut to play automatically upon changing rooms and entering rooms, so I won't need to copy and paste the code for every room.

There's on_event that lets you trigger things in case of few common events:
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html#on_event

Gal Shemesh

Thanks @RootBound & @Crimson Wizard!

I followed the suggestion here and made a black GUI for my custom fades.

I will sure check the scenario with the rep-exec-always. I never tried this and it sounds interesting.

Regarding the Tween module, I tried using it but got errors... My feault probably. Will need to re-read the instructions and to perhaps try it on a clean project rather than on my current one which has too many things in it already.

As for the on_event - thanks a million! What a great feature - just removed all the manual NewFadeIn() and NewFadeOut() calls that I made and put them one in a 'eEventEnterRoomAfterFadein' and the other in 'eEventLeaveRoom'. That works fantastic and will save me a lot of work. :)
Gal Shemesh,
goldeng

Cassiebsg

To use it without a wait(1), I would just create an int (in Global Variables), and then add to the int, once the "timer" (int) reaches the amount you decide, you change the transparency, reset the int, and start counting again, until the next transparency is reached.

Basically, you create a manual timer.
Not sure if you could use a while loop, or need to put the code in rep_exe_always... Try the while first and see if it works.  ;)

Keep in mind: 1 second = 40 FPS (it's the default of AGS, if you haven't change it).
There are those who believe that life here began out there...

Gal Shemesh

Quote from: Crimson Wizard on Mon 07/08/2023 15:51:16If your meaning is to play a sequence of actions in parallel to your fade effect, then you would have to implement  a cutscene/sequence state check in repeatedly_execute_always. This may go two ways:
1) play fade effect in a loop with Wait(1) inside, while running & checking for other actions in rep-exec-always
2) script fade effect in rep-exec-always without Wait, advancing its transparency step-by-step with every rep-exec call. This will allow to trigger it, and then play any sequence of blocking actions, while the Fade effect is running in "background".
Option 2 looks interesting. I tried to take my custom fade function from the GlobalScript header and to put it inside the rep-exec-always in the GlobalScript to calling it from there, but it tells me that nested functions aren't supported. I guess I misunderstood something...
Gal Shemesh,
goldeng

Crimson Wizard

#26
Quote from: Gal Shemesh on Mon 07/08/2023 21:24:36Option 2 looks interesting. I tried to take my custom fade function from the GlobalScript header and to put it inside the rep-exec-always in the GlobalScript to calling it from there, but it tells me that nested functions aren't supported. I guess I misunderstood something...

Well, of course function cannot be placed inside another function. A call to function may be.

But if you go rep-exec-always way, then you should not be calling your custom fade in from there. Or rather you should not call anything that takes time from there.

The idea with rep-exec-always is that you only run one step at a time, while checking if you need to stop.

Code: ags
bool FadingOut;

function repeatedly_execute_always()
{
    if (FadingOut)
    {
        if (gFade.Transparency == 0)
        {
            FadingOut = false; // process completed
        }
        else
        {
            gFade.Transparency -= 2;
        }
    }
}

With this you also need a function that starts the process, but does not continue it itself.
Code: ags
function MyFadeOut()
{
    FadingOut = true;
    gFade.Transparency = 100;
}

This is essentially what the Tween module is doing inside.

Or, you can make a function that works in both modes:
Code: ags
function MyFadeOut(BlockingStyle block)
{
    FadingOut = true;
    gFade.Transparency = 100;
    if (block == eBlock)
    {
         while (gFade.Transparency > 0)
         {
              gFade.Transparency -= 2;
              Wait(1);
         }
         FadingOut = false;
    }
}



ARGH, but this all must be explained in the manual, as a part of some tutorial, because similar explanation was posted numerous times on forums. I lost count to how many times I personally reposted this.

Gal Shemesh

Thanks so much @Crimson Wizard. You help me a lot and no doubt to many others. Sorry if my queries required you to repeat yourself. I'll try to take it from here to see how I can tune it to meet my needs. Many thanks again. :)
Gal Shemesh,
goldeng

Crimson Wizard

Quote from: Gal Shemesh on Mon 07/08/2023 22:10:28Sorry if my queries required you to repeat yourself.

Well, it's inevitable, because the manual is not getting filled in with this information. I wish i could simply link to an article, but it's not there.

I need to find spare time and write it once.

SMF spam blocked by CleanTalk