Jibble

Author Topic: Display function blocking animated backgrounds  (Read 264 times)

Display function blocking animated backgrounds
« on: 12 Apr 2019, 15:17 »
Hi all,

I have a couple of very simple questions so I thought I'd lump them both together in one post, hope that's ok:

1) I'm using the Display function to display messages on screen, but this blocks background animations. Is there a way around this?

2) My game has only one action and two cursors, "neutral/no action" and "interact". I want the cursor to change from an arrow to a hand when it's over a hotspot or object, so I used this code in repeteadly_execute which I believe was contributed by Khris and uses a custom property called def_curs:

Code: Adventure Game Studio
  1.   int mm = mouse.Mode;
  2.   int nm;     // new mode
  3.   Hotspot*h;
  4.   Object*o;
  5.   int lt = GetLocationType(mouse.x, mouse.y);   // what's under the cursor?
  6.  
  7.   if (mm != eModeUseinv) {
  8.     if (lt == eLocationNothing) nm = eModeLookat;
  9.     if (lt == eLocationHotspot) {
  10.       h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  11.       nm = h.GetProperty("def_curs");
  12.     }
  13.     if (lt == eLocationObject) {
  14.       o = Object.GetAtScreenXY(mouse.x, mouse.y);
  15.       nm = o.GetProperty("def_curs");
  16.     }
  17.     if (lt == eLocationCharacter) {
  18.       nm = eModeTalkto;
  19.     }
  20.  
  21.     if (nm != mm) mouse.Mode = nm;  // only change if necessary to not disturb animated cursors
  22.  

However, I find that this much simpler version also works for me:

Code: Adventure Game Studio
  1.    
  2.   int mm = mouse.Mode;
  3.   int nm;     // new mode
  4.   int lt = GetLocationType(mouse.x, mouse.y);   // what's under the cursor?
  5.  
  6.   if (mm != eModeUseinv) {
  7.     if (lt == eLocationNothing) nm = eModeLookat;
  8.     if (lt == eLocationHotspot || lt == eLocationObject) nm = eModeInteract;
  9.     if (nm != mm) mouse.Mode = nm;  // only change if necessary to not disturb animated cursors
  10.  
  11.  

So this is question is more about curiosity, really. What is the purpose of using a custom property in the original code? Are there other situations, more complex than my scenario, in which it would be necessary?

Thanks a lot in advance!

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Re: Display function blocking animated backgrounds
« Reply #1 on: 12 Apr 2019, 15:46 »
1) You can either create a GUI of your own for the text, or move all your BG animations to rep_exec_always... I'm guessing the first one might be easier. ;)

2) I'll leave the experts answer this one, cause I normally just the @OVERHOTSPOT@ ...  ;)
There are those who believe that life here began out there...

Re: Display function blocking animated backgrounds
« Reply #2 on: 12 Apr 2019, 15:53 »
1) You can either create a GUI of your own for the text, or move all your BG animations to rep_exec_always... I'm guessing the first one might be easier. ;)

2) I'll leave the experts answer this one, cause I normally just the @OVERHOTSPOT@ ...  ;)

Thank you! It has indeed crossed my mind to create a GUI for the text, but that would mean that I would have to replace every instance of Display I already have in my game with this new GUI, right?  :~(

Re: Display function blocking animated backgrounds
« Reply #3 on: 12 Apr 2019, 16:06 »
1) I'm using the Display function to display messages on screen, but this blocks background animations. Is there a way around this?

I'd suggest same solution as Cassiebsg here: to make your own GUI with a label looking like Display box (you would have to script its resizing to accomodate the text and maybe drawing too if you need to change the looks) and then display it in semi-blocking way like this:
Code: Adventure Game Studio
  1. gMyDisplay.Visible = true;
  2. while (WaitMouseKey(1) == 0); // wait until player clicks or presses a key
  3. gMyDisplay.Visible = false;
  4.  
For convenient usage this may be put in a function:
Code: Adventure Game Studio
  1. void MyDisplay(String text)
  2. {
  3.     lblMyDisplay.Text = text; // assign label
  4.     // do resizing and stuff
  5.     gMyDisplay.Visible = true;
  6.     while (WaitMouseKey(1) == 0); // wait until player clicks or presses a key
  7.     gMyDisplay.Visible = false;
  8. }
  9.  
then you can call it like you call Display, except you cannot use string formatting directly and will have to use String.Format if you need one.

Simply do Replace All to replace Display with MyDisplay everywhere, and fix remaining formatting if there's any.


So this is question is more about curiosity, really. What is the purpose of using a custom property in the original code? Are there other situations, more complex than my scenario, in which it would be necessary?

Custom property let you define different cursor for particular object or hotspot. Set up default property value to ones you like and leave it until you have a need to make an exception.
« Last Edit: 12 Apr 2019, 16:11 by Crimson Wizard »

Re: Display function blocking animated backgrounds
« Reply #4 on: 12 Apr 2019, 16:25 »
CW, fantastic, thanks a lot! I think it might be worth giving this a try.

While I was working on the side, however, I have now run into literally the opposite problem: I have a "Pause menu" GUI that pops up when the player presses the Esc key and it's set to "Pause game when shown". However, in this case, the background animations keep going. What is this sorcery? Isn't pausing the game supposed to be a fully blocking function?

Re: Display function blocking animated backgrounds
« Reply #5 on: 13 Apr 2019, 12:05 »

I'd suggest same solution as Cassiebsg here: to make your own GUI with a label looking like Display box (you would have to script its resizing to accomodate the text and maybe drawing too if you need to change the looks) and then display it in semi-blocking way like this:
Code: Adventure Game Studio
  1. gMyDisplay.Visible = true;
  2. while (WaitMouseKey(1) == 0); // wait until player clicks or presses a key
  3. gMyDisplay.Visible = false;


Hey CW, I tested this and I'm getting a "PE04: Parse error at ';'" error here in the "while" function. It looks like this needs a statement in order to parse properly, because if I put anything there (for example, moving the "gMyDisplay.Visible = true;" statement inside the while function), then it works.

Another problem that I'm getting is that now the cursor disappears when the text is shown. It's not disabled, because if I move it around and then click or press a key, the cursor reappears in the spot that I moved it to. So it's actually working and moving, but apparently it's invisible until gMyDisplay is not visible again.

Any idea what could be happening here, by any chance?


EDIT: OK, got it. the while function triggers a change to the "Wait" cursor, which I didn't have a sprite for. Solved!

I'm still wondering about the need for a statement in that while function (right now I have something that won't interfere with anything else, simply a "mouse.Visible = true" statement, but it feels kind of lame and hacky tbh), and regarding the last question I asked yesterday, I would love to know why, when I pop up my "Pause" GUI, the background animations keep going.

In any case, thanks a lot again, CW, your approach works beautifully and I'm definitely going to replace all instances of the normal "Display" in my game with this!  (nod)
« Last Edit: 13 Apr 2019, 12:25 by notarobotyet »