Player sprite stops when mouse hovers over object

Started by JackAnimated, Sun 17/08/2014 23:17:40

Previous topic - Next topic

JackAnimated

So I have asome script in a room which looks like this:

Quote
function hBed_MouseMove()
{
Display("bunk");
}

When the word "bunk" comes up, all movement on the screen (player sprite) stops.

How can I have the word hover up when the curser is over something without stopping the action?



Thanks.

Snarky

Basically: Create a GUI with a GUI Label for the text (in the GUI part of the AGS editor). When you want to display it (in the script), set the text of the label to the word, and set the GUI visibility to true.

The concept of a "tooltip" showing the name of hotspots/objects/characters when you mouseover is very common, and I'm pretty sure there are modules to take care of it for you (and if not, definitely several code samples on the forum).

JackAnimated

That's cool. But do I need to do that for every hotspot in the game?

Is it possible to write code which say:

QuoteIf (function.mouse is over hotspot)
    {show.text = hotspot description}

?



Thanks.

Crimson Wizard

#3
Use "@OVERHOTSPOT@". This is a magic word that is substituted by hotspot name.

Alternatively,
Code: ags

Hotspot *h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
if (h != null)
   label.Text = h.Name;



There are also several existing game templates that have similar functionality. You may check them to see an example (or just use them for your game).
One of them is 9-verb Monkey Island template which comes with AGS.
Also:
http://www.adventuregamestudio.co.uk/forums/index.php?topic=48441.0
http://www.adventuregamestudio.co.uk/forums/index.php?topic=48638.0

Snarky

Yes, CW's solution is good and works for most simple cases (in the code example, you'll probably want to display the label when the cursor is over objects, characters and maybe GUIs as well, but that's simple to add). Stick the code (if you use that solution) in the global script repeatedly_execute() function.

Even though there are many modules and templates that will do it for you (here's another one: http://www.adventuregamestudio.co.uk/forums/index.php?topic=49970.0), it's worth writing your own because it's relatively simple and teaches you about a number of different AGS concepts.

JackAnimated

Thanks peeps.

So I am using this code now, which works a treat:

QuoteHotspot *h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
   if (h != null)
   lHover.Text = h.Name;

Except that when I am not hovering over a hotspot, the label displays "no hotspot". How can I change this to BLANK or some other wording?

Snarky

Code: AGS
Hotspot *h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
if (h != null)
   lHover.Text = h.Name;
else
   lHover.Text = "";


Also, learn and apply the standard rules for indenting your code. It's simple, and will save you from a world of trouble down the road.

Crimson Wizard

#7
Quote from: JackAnimated on Mon 18/08/2014 11:37:13
Except that when I am not hovering over a hotspot, the label displays "no hotspot". How can I change this to BLANK or some other wording?

Duh! I forgot this again. :)

Code: ags

if (h != hotspots[0])
   lHover.Text = h.Name;
else
   lHover.Text = "";

Hotspot[0] is everywhere where there is no other hotspots.

Also, have you tried setting label to "@OVERHOTSPOT@"? That will work for objects and characters too.
The code snippet I posted is just an example of how these things work.

JackAnimated

Ah I see. Thanks both. Just tried @overhotspot@. That's perfect, but the code is interesting too.

Khris

Just for reference, there's also Game.GetLocationName().

JackAnimated

When using @overhotspot@ , where is the font size defined? Can I change it?

Crimson Wizard

@overhotspot@ does not define a font. Your Label does. Edit Label's Font property.

JackAnimated

There is nothing about font size in label properties.

Slasher

You need to import a new font of right type and size and use that for the label font.

Crimson Wizard

Oh, yes, sorry, you were asking about the size.
As slasher sais, you have to import a new font (or, if your font is TTF, import it as a new font with different size). AGS works with way...

JackAnimated

New question: How can I display the name of an OBJECT in the label text?

Crimson Wizard

#16
Quote from: JackAnimated on Wed 27/08/2014 18:50:58
New question: How can I display the name of an OBJECT in the label text?
Generally this:
Code: ags

lblLabel.Text = oObject.Name;


Or, are you looking to display the name of an object under mouse cursor? In which case "@overhotspot@" should work too...


SMF spam blocked by CleanTalk