Display function blocking animated backgrounds

Started by Laura Hunt, Fri 12/04/2019 15:17:57

Previous topic - Next topic

Laura Hunt

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: ags

  int mm = mouse.Mode;
  int nm;     // new mode
  Hotspot*h;
  Object*o;
  int lt = GetLocationType(mouse.x, mouse.y);   // what's under the cursor?

  if (mm != eModeUseinv) {
    if (lt == eLocationNothing) nm = eModeLookat;
    if (lt == eLocationHotspot) {
      h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
      nm = h.GetProperty("def_curs");
    }
    if (lt == eLocationObject) {
      o = Object.GetAtScreenXY(mouse.x, mouse.y);
      nm = o.GetProperty("def_curs");
    }
    if (lt == eLocationCharacter) {
      nm = eModeTalkto;
    }

    if (nm != mm) mouse.Mode = nm;  // only change if necessary to not disturb animated cursors


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

Code: ags

    
  int mm = mouse.Mode;
  int nm;     // new mode
  int lt = GetLocationType(mouse.x, mouse.y);   // what's under the cursor?

  if (mm != eModeUseinv) {
    if (lt == eLocationNothing) nm = eModeLookat;
    if (lt == eLocationHotspot || lt == eLocationObject) nm = eModeInteract;
    if (nm != mm) mouse.Mode = nm;  // only change if necessary to not disturb animated cursors



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

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...

Laura Hunt

Quote from: Cassiebsg on Fri 12/04/2019 15:46:40
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?  :~(

Crimson Wizard

#3
Quote from: notarobotyet on Fri 12/04/2019 15:17:57
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: ags

gMyDisplay.Visible = true;
while (WaitMouseKey(1) == 0); // wait until player clicks or presses a key
gMyDisplay.Visible = false;

For convenient usage this may be put in a function:
Code: ags

void MyDisplay(String text)
{
    lblMyDisplay.Text = text; // assign label
    // do resizing and stuff
    gMyDisplay.Visible = true;
    while (WaitMouseKey(1) == 0); // wait until player clicks or presses a key
    gMyDisplay.Visible = false;
}

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.


Quote from: notarobotyet on Fri 12/04/2019 15:17:57
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.

Laura Hunt

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?

Laura Hunt

#5
Quote from: Crimson Wizard on Fri 12/04/2019 16:06:07

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: ags

gMyDisplay.Visible = true;
while (WaitMouseKey(1) == 0); // wait until player clicks or presses a key
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)

SMF spam blocked by CleanTalk