Future suggestion: A way to show custom room exit cursors (with code)

Started by alex, Tue 24/02/2009 17:25:13

Previous topic - Next topic

alex

Here is what I am currently using.  Perhaps there is an easier way.  But the basic behavior I have achieved lets me define custom exit cursors when hovering over hotspots set up for top, bottom, left and right exits, returning to the previous cursor automatically when the mouse exits the hotspot or the room is changed.

I added this function to the global script:

Code: ags
//Check if the cursor is over a hotspot defined as an exit and change the visual accordingly

function check_cursor()
{
  if (GetLocationType(mouse.x,mouse.y)==eLocationHotspot){
    Hotspot* h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
    if (h.GetTextProperty("Exit") == "Top")
    {
      mouse.SaveCursorUntilItLeaves();
      mouse.Mode = eModeWalkto;
      mouse.UseModeGraphic(eModeExitTop);
    }
    else if (h.GetTextProperty("Exit") == "Bottom")
    {
      mouse.SaveCursorUntilItLeaves();
      mouse.Mode = eModeWalkto;
      mouse.UseModeGraphic(eModeExitBot);
    }
    else if (h.GetTextProperty("Exit") == "Left")
    {
      mouse.SaveCursorUntilItLeaves();
      mouse.Mode = eModeWalkto;
      mouse.UseModeGraphic(eModeExitLeft);
    }
    else if (h.GetTextProperty("Exit") == "Right")
    {
      mouse.SaveCursorUntilItLeaves();
      mouse.Mode = eModeWalkto;
      mouse.UseModeGraphic(eModeExitRight);
    }
    h = null;
  }
}


Which is called from the repeatedly_execute function:

Code: ags
function repeatedly_execute() {
  
  // put anything you want to happen every game cycle, even when
  // the game is paused, here
  
  if (IsGamePaused() == 1) return;

  // put anything you want to happen every game cycle, but not
  // when the game is paused, here
  
  // Check if the mouse cursor is over a hotspot defined as an exit
  check_cursor();

}


Add 4 cursors to the list of mouse cursors named ExitTop, ExitBot, ExitLeft and ExitRight, for top, bottom, left and right exits respectively.  Set up the sprites and hotspots for each, leave everything else as default.

Edit the schema to add a new text property called Exit.  Set it's default value to No (or indeed anything that is not "Left, Right, Top or Bottom").

Now, whenever you want to use a custom exit cursor, draw a hotspot over your exit, give it whatever name you want.  You can then edit the "Exit" property to be either "Left", "Right", "Top", "Bottom" to use the respective cursor.

Even if this (or similar) behavior doesn't make the next version, I hope it's useful to someone.

( I did look and didn't find a built in "exit cursor" function - but if there is one it will be the second time today I pull my foot out of my mouth)

SSH

You know that there are Room.LeftEdge, Room.RightEdge, etc. variables built-in to AGS, right?

This code might be useful to those who have irregular shaped exits, though. Why not turn it into a module?

CJ usually doesn't prioritise suggestions that can be implemented easily in script code, anyway as the customizability that most developers want means they'd have to recode it manually anyway...
12

alex

Yeah I know about the edge variables.  They don't work if I have say, a top exit halfway down the screen, such as a door in a facing wall, if there are items on that wall I want to look at.

The thing is this is more than just the code, there is extra step of adding the 4 cursors and setting up the parameters accordingly.

People are welcome to do whatever they want with my suggestions.  They are put out there with a no obligation to use policy.

SSH

Quote from: alex on Tue 24/02/2009 17:44:52
Yeah I know about the edge variables.  They don't work if I have say, a top exit halfway down the screen, such as a door in a facing wall, if there are items on that wall I want to look at.

Code: ags

if (Hotspot.GetAtScreenXY(mouse.x, mouse.y)!=null) {
   // Do hotspot stuff
} else if (mouse.y<Room.TopEdge) {
  // Do top edge stuff
}


covers that scenario...
12

alex

Hmm good thinking...  Though I guess either way works.

The advantage of the hotspot method I have proposed is that you can use it in conjunction with one of the mouseover description modules to give your room exits unique names like "Exit to park" or "North to dark scary woods".

But thanks for the extra suggestion, I'll try it out and see how it works.  Cheers :)

SMF spam blocked by CleanTalk