Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: JackAnimated on Sun 17/08/2014 23:17:40

Title: Player sprite stops when mouse hovers over object
Post by: JackAnimated on Sun 17/08/2014 23:17:40
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.
Title: Re: Player sprite stops when mouse hovers over object
Post by: Snarky on Sun 17/08/2014 23:48:34
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).
Title: Re: Player sprite stops when mouse hovers over object
Post by: JackAnimated on Mon 18/08/2014 00:31:31
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.
Title: Re: Player sprite stops when mouse hovers over object
Post by: Crimson Wizard on Mon 18/08/2014 00:53:31
Use "@OVERHOTSPOT@". This is a magic word that is substituted by hotspot name.

Alternatively,
Code (ags) Select

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
Title: Re: Player sprite stops when mouse hovers over object
Post by: Snarky on Mon 18/08/2014 01:21:21
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.
Title: Re: Player sprite stops when mouse hovers over object
Post by: JackAnimated on Mon 18/08/2014 11:37:13
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?
Title: Re: Player sprite stops when mouse hovers over object
Post by: Snarky on Mon 18/08/2014 12:08:49
Code (AGS) Select
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.
Title: Re: Player sprite stops when mouse hovers over object
Post by: Crimson Wizard on Mon 18/08/2014 12:09:35
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) Select

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.
Title: Re: Player sprite stops when mouse hovers over object
Post by: JackAnimated on Mon 18/08/2014 12:27:22
Ah I see. Thanks both. Just tried @overhotspot@. That's perfect, but the code is interesting too.
Title: Re: Player sprite stops when mouse hovers over object
Post by: Khris on Mon 18/08/2014 12:59:31
Just for reference, there's also Game.GetLocationName().
Title: Re: Player sprite stops when mouse hovers over object
Post by: JackAnimated on Mon 25/08/2014 00:30:58
When using @overhotspot@ , where is the font size defined? Can I change it?
Title: Re: Player sprite stops when mouse hovers over object
Post by: Crimson Wizard on Mon 25/08/2014 00:33:15
@overhotspot@ does not define a font. Your Label does. Edit Label's Font property.
Title: Re: Player sprite stops when mouse hovers over object
Post by: JackAnimated on Mon 25/08/2014 16:46:18
There is nothing about font size in label properties.
Title: Re: Player sprite stops when mouse hovers over object
Post by: Slasher on Mon 25/08/2014 16:56:47
You need to import a new font of right type and size and use that for the label font.
Title: Re: Player sprite stops when mouse hovers over object
Post by: Crimson Wizard on Mon 25/08/2014 17:00:39
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...
Title: Re: Player sprite stops when mouse hovers over object
Post by: JackAnimated on Wed 27/08/2014 18:50:58
New question: How can I display the name of an OBJECT in the label text?
Title: Re: Player sprite stops when mouse hovers over object
Post by: Crimson Wizard on Wed 27/08/2014 19:20:07
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) Select

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...
Title: Re: Player sprite stops when mouse hovers over object
Post by: JackAnimated on Wed 27/08/2014 19:39:28
Totally worked dude :D