Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gal Shemesh on Thu 03/08/2023 13:02:54

Title: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Thu 03/08/2023 13:02:54
Hi everyone,

Trying to solve this one out myself but kind of stuck...

I'm willing to keep the mouse cursor visible with the 'Wait()' sprite when Fade-In and Fade-Out transitions are playing. But Can't find a way to doing so - whenever a fade is playing, either by the 'player.ChangeRoom()' function or manually by using 'FadeIn()' and 'FadeOut()' functions the cursor gets hidden.

Thanks

EDIT:
Not sure if this is the right way to doing it, but I just ended up making a hidden 'gWait' GUI that I set with the Wait cursor sprite and size, and set it to follow the X and Y positions of the mouse cursor in the repeatedly_execute() function. Then I made a custom function that is called when clicking on the main menu buttons, and in it I set the 'gWait' GUI to show up, then I set a FadeOut() transition to play, and right after it before changing the room I made the 'gWait' GUI to be hidden again.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Cassiebsg on Fri 04/08/2023 22:13:38
Seems like you solved it yourself :)
But to answer your original question, as far as I know, you can't show the cursor during the built in fade out and fade in.

The solution is of course to code your own fade effect, like you did (GUI or Room, and set fade to instant).
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Sat 05/08/2023 10:52:04
Thanks @Cassiebsg. :) That's another thing I tried solving which remained opened. I just can't find a way to make the fake 'Wait' cursor (the GUI I made) to keep showing on-top of the fade when it plays - in other words, to exclude it from the fade transitions; the transitions affect it even if I set the default fade to Instant and use the FadeIn() / FadeOut() functions...
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Snarky on Sat 05/08/2023 13:13:31
Am I crazy, or is this whole problem just a matter of setting the Wait cursor image to an actual cursor rather than a blank sprite?

To explain a little further: in AGS, when the game is blocked from player input, the cursor is set to the Wait cursor mode. This cursor mode can have a special cursor image, for example an hourglass or a stopwatch, but in many games it is simply set to be invisible instead. That's why the cursor disappears when the game blocks. If you instead set it to a normal cursor image, it should show up normally, but of course then there won't be any visual indication that the game is not currently responding to player input.

Quote from: Gal Shemesh on Sat 05/08/2023 10:52:04I just can't find a way to make the fake 'Wait' cursor (the GUI I made) to keep showing on-top of the fade when it plays - in other words, to exclude it from the fade transitions; the transitions affect it even if I set the default fade to Instant and use the FadeIn() / FadeOut() functions...

If your pseudocursor is on a GUI and your custom fade relies on a fullscreen black GUI, then it's just a matter of setting up the GUI z-order to decide whether the "cursor" is in front of or behind the black screen.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Khris on Sat 05/08/2023 14:22:01
I checked this in the Tumbleweed template; the wait cursor is the crosshairs but it disappears during the fade. So I don't think it's just a matter of a missing Wait cursor sprite.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Snarky on Sat 05/08/2023 14:46:44
Quote from: Khris on Sat 05/08/2023 14:22:01I checked this in the Tumbleweed template; the wait cursor is the crosshairs but it disappears during the fade. So I don't think it's just a matter of a missing Wait cursor sprite.

Yeah, the in-engine fade might have some special voodoo, but in that case I wouldn't expect that doing anything in repeatedly_execute_always() would work either. But the custom fade method should certainly work if the Wait cursor sprite is set.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Nahuel on Sat 05/08/2023 15:13:27
It would be possible then to create a function for fade in and out adding custom behaviour for something like player.ChangeToRoom(int room_id, int x, int y, ...) with optional x and y. And add a GUI and can be use in conjunction with Tween Module to fade out and fade in but adding on game_start SetScreenTransition(eTransitionInstant)


SetScreenTransition (https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Screen.html?highlight=transition&case_sensitive=0#setscreentransition)
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Sat 05/08/2023 15:24:57
Quote from: Snarky on Sat 05/08/2023 14:46:44If your pseudocursor is on a GUI and your custom fade relies on a fullscreen black GUI, then it's just a matter of setting up the GUI z-order to decide whether the "cursor" is in front of or behind the black screen.
Thanks for the suggestion. However, not matter what high number I put in the ZOrder, the cursor remains below the transition...
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Crimson Wizard on Sat 05/08/2023 15:50:33
Quote from: Gal Shemesh on Sat 05/08/2023 15:24:57Thanks for the suggestion. However, not matter what high number I put in the ZOrder, the cursor remains below the transition...

Are you using FadeOut/FadeIn functions for translation, or a GUI?
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Sat 05/08/2023 16:10:07
Quote from: Crimson Wizard on Sat 05/08/2023 15:50:33Are you using FadeOut/FadeIn functions for translation, or a GUI?
Just the built-in transitions, either the default behavior of FadeInAndOut or manually calling for them with the FadeIn() and FadeOut() functions.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Crimson Wizard on Sat 05/08/2023 16:38:17
Quote from: Gal Shemesh on Sat 05/08/2023 16:10:07
Quote from: Crimson Wizard on Sat 05/08/2023 15:50:33Are you using FadeOut/FadeIn functions for translation, or a GUI?
Just the built-in transitions, either the default behavior of FadeInAndOut or manually calling for them with the FadeIn() and FadeOut() functions.

The mentioned method of adding zorder is for when you are using GUI as a fadeout.

This thread mentioned several separate methods:
- built-in fadeout run during transition;
- calling FadeIn/Out yourself in script.
- using GUI to fade the screen.

First of all, I believe the mouse cursor will only stay above the fade effect if you are using GUI. It never is drawn above a built-in fade effect, regardless of how it's run (by a script command, or automatically during transition).

Secondly, if you're using gui as a replacement for the mouse cursor, then you also need to adjust it's zorder to be higher than the "fade" gui.

EDIT:
in regards to the Wait cursor:
The Wait cursor is NOT shown during fade, regardless of how Fade is run.
Testing FadeIn/Out commands, I can see that the cursor disappears completely during FadeIn, but not manual FadeOut (idk why).
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Sat 05/08/2023 16:40:49
Appearantly I mixed between the methods. Thanks @Crimson Wizard for the clarification. :)
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Cassiebsg on Sat 05/08/2023 19:22:45
Forget about the built in fade in and fade out. Write your own, using a GUI, it's easy and it'll solve all your problems. That means you set in the setting the effect to instant, and instead you just turn on the GUI, fade (change transparency from 0% to 100%) the GUI to black, change room instantly, and then fade to normal to the new room. This will keep your cursor behaving normally.

And then instead of using FadeIn() and FadeOut(), you just use MyFadeIn() and MyFadeOut(). (and you can just use a find & replace in script. ;)

And of course, you need to set the wait cursor to the same sprite you normally use (or a special one you might want).
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Sat 05/08/2023 19:35:06
Quote from: Cassiebsg on Sat 05/08/2023 19:22:45Forget about the built in fade in and fade out. Write your own, using a GUI, it's easy and it'll solve all your problems. That means you set in the setting the effect to instant, and instead you just turn on the GUI, fade (change transparency from 0% to 100%) the GUI to black, change room instantly, and then fade to normal to the new room. This will keep your cursor behaving normally.

And then instead of using FadeIn() and FadeOut(), you just use MyFadeIn() and MyFadeOut(). (and you can just use a find & replace in script. ;)

And of course, you need to set the wait cursor to the same sprite you normally use (or a special one you might want).
Yep, that would probably be the best way to doing it. Though, the pure black is considered as transparent... Any way to make my GUI color a solid black instead of using a background image?
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Crimson Wizard on Sat 05/08/2023 19:56:31
Quote from: Gal Shemesh on Sat 05/08/2023 19:35:06Yep, that would probably be the best way to doing it. Though, the pure black is considered as transparent... Any way to make my GUI color a solid black instead of using a background image?

Apprently not, because it's AGS.

The closest you may with the BackgroundColor is RGB 0;4;0.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Sat 05/08/2023 20:09:36
Hah hah, "Because it's AGS" :-D I like this comment.

Thanks @Crimson Wizard. Then I'll just use a pure black graphic that covers the whole screen. It's nice that this method of 'fade' using a GUI keeps showing the mouse cursor with the Wait cursor like @Cassiebsg has mentioned, so I disregarded the fake 'Wait' cursor GUI I made altogether. :)
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Laura Hunt on Sat 05/08/2023 20:14:23
I always use BackgroundColourNumber 32 (or like CW said, 0,4,0) as the background colour of any black GUIs I might need for fades and other stuff. Maybe it's not technically pure black, but I've never been able to tell the difference.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Snarky on Sat 05/08/2023 20:33:50
What happens if you set it to 65536? (https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-trublu-v3-0-get-true-color-blues-and-magenta-in-32-bit-games!/)

(Personally I usually just import a fullscreen black sprite.)
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Sun 06/08/2023 08:30:27
Quote from: Snarky on Sat 05/08/2023 20:33:50What happens if you set it to 65536? (https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-trublu-v3-0-get-true-color-blues-and-magenta-in-32-bit-games!/)

(Personally I usually just import a fullscreen black sprite.)
Me too. But just tried 65536, took a screenshot of it and went to check the color with the eye-dropper tool in Photoshop and what do you know - PURE BLACK! RGB values are 0,0,0. :-D Thanks!

When I set it to 65536 then in AGS, the RGB are shown as 0,0,0 and the Hue, Sat and Lum values are 160,0,0. But if I set the RGB and the Hue, Sat and Lum values manually then the transparent index takes over. So I guess using the actual color number is the better way of setting up colors in AGS. I wonder what's the equivalent for pure white of 255,255,255 then, as in AGS white gets 248,252,248.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Snarky on Sun 06/08/2023 09:47:47
You could try using the TruBlu module's GetColorFromTrueColorRGB(255,55,255);

I'm not sure it will work. The AGS color system is an insane mess, and that it's possible to use above-16-bit color values at all is unintentional behavior, so no guarantees. (I actually thought the 248,252,248 problem had been fixed a long time ago, though.)

If that doesn't work, you can use color 15, which is at least neutral.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Mon 07/08/2023 12:55:10
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

Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: RootBound on Mon 07/08/2023 15:47:00
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.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Crimson Wizard on Mon 07/08/2023 15:51:16
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
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Mon 07/08/2023 17:04:25
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. :)
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Cassiebsg on Mon 07/08/2023 21:22:17
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).
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Mon 07/08/2023 21:24:36
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...
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Crimson Wizard on Mon 07/08/2023 21:31:48
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) Select
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) Select
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) Select
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.
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Gal Shemesh on Mon 07/08/2023 22:10:28
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. :)
Title: Re: Keep showing the mouse cursor on FadeIn and FadeOut
Post by: Crimson Wizard on Mon 07/08/2023 22:14:41
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.