Map Question: Text Over Hotspot

Started by metalmario991, Fri 24/11/2017 02:55:59

Previous topic - Next topic

metalmario991

In my game there is a map area, similar to the ones seen in Monkey Island. I want it so that when you hover over a location you can go to, text shows up above
the cursor telling you what the location is, just like Monkey Island. I was wondering how to do it because I can't find any other post or tutorial about it.

Khris

To display text at an arbitrary location on the screen, you can use a textual overlay or a GUI with a label.
Add the "enters room after fadein" and "repeatedly_execute" events to your map room so AGS creates the respective functions in the room script.

The put code in them like this:
Code: ags
function room_AfterFadein() {
  gCursor.Visible = true;
}

function room_RepExec() {
  lblHotspot.Text = Game.GetLocationName(mouse.x, mouse.y);
  gCursor.SetPosition(mouse.x - gCursor.Width / 2, mouse.y - 15);
}


You'll also need to create a GUI called gCursor, then put a label on it called lblHotspot. Set the GUI's visibility to "Normal, initially off" and make it as tall as your font, something like 10 or 12 pixels, and wide enough so your location descriptions fit into a single line. Make the label as big as the GUI and set the text alignment to centered.

If some of your hotspots are close to the edge of the screen, the text might be cut off. If that's an issue, you can adjust the GUI's coordinates using this:
Code: ags
function room_RepExec() {
  lblHotspot.Text = Game.GetLocationName(mouse.x, mouse.y);
  int x = mouse.x - gCursor.Width / 2;
  if (x < 3) x = 3;
  if (x + gCursor.Width > System.ViewportWidth - 3) x = System.ViewportWidth - 3 - gCursor.Width;
  gCursor.SetPosition(x, mouse.y - 15);
}

SMF spam blocked by CleanTalk