mouse over hotspot -display name of hotspot over coursor

Started by julius, Tue 29/06/2010 06:30:22

Previous topic - Next topic

julius

how do i make ags display a name of an object over the mouse coursor when i move the coursor over a hotspot?

i guese i click on "mouse move over hotspot" action , but what do i put in the script??

Rulaman

It's really simple.

Make a gui (transparent if you wish) and place a label on it.
As label text write simple @OVERHOTSPOT@.
Make the GUI visible and place it somewhere on your screen.

In the manual search for: Interface text
@OVERHOTSPOT@ Name of the hotspot which the cursor is over

Greetings
Rulaman
Zak: Komm mit mir Sushi.
Zak: Come with me Sushi.

barefoot

Hi

Maybe above post is what you need if you are looking for objects actual name etc..

anyhow.. the below is still useful to know,,

well, mouse over hotspot displays text etc as normal, you can put what you like such as:

Code: ags

function hHotspot1_MouseMove()
{
cprof_plum.Say("Look, there's a door Indy");
}


This can be quite useful as you dont need to change cursor mode, thats if you really need it..

-barefoot-
I May Not Be Perfect but I Have A Big Heart ..

julius

Quote from: Rulaman on Tue 29/06/2010 07:28:06
It's really simple.

Make a gui (transparent if you wish) and place a label on it.
As label text write simple @OVERHOTSPOT@.
Make the GUI visible and place it somewhere on your screen.

In the manual search for: Interface text
@OVERHOTSPOT@ Name of the hotspot which the cursor is over

Greetings
Rulaman


first of all thanks for the quick reply ,
but i have a quastion: the gui i created will be displayed at a fix place , i would like to place it over where the mouse coursor is...(like in so many lucasarts games like the dig monkey island and so on).

barefoot

well, you can adjust x and y for the GUI where you would like it displayed, if thats any use?

-barefoot-
I May Not Be Perfect but I Have A Big Heart ..

julius

yes but the mouse coursor allways moves how do i make the hotspot name move with it??

Khris

You'd put the lines inside repeatedly_execute, a function in Global.asc that's executed every game loop.

Code: ags
  // small offset from mouse cursor hotspot
  int x = mouse.x+3;
  int y = mouse.y+3;

  GUI*g = gCursor;  // change gCursor to the scriptname of your GUI

  // make sure new coordinates are within screen limits
  if (x > 320-g.Width) x = 320-g.Width;
  if (y > 240-g.Height) y = 240-g.Height;

  // reposition gui
  g.SetPosition(x, y);


There's room for improvement; e.g. if you cursor is a TheDig style cross, you could move the text to the upper corner in the lower half and left corner in the right half of the screen.
Or you could keep it in one place while the mouse is still over the hotspot.

What you want to keep in mind is that for global behavior like this, you never, ever use functions specific to a single hotspot, like barefoot suggested in his first post.

julius

Quote from: Khris on Tue 29/06/2010 10:43:10
You'd put the lines inside repeatedly_execute, a function in Global.asc that's executed every game loop.

Code: ags
  // small offset from mouse cursor hotspot
  int x = mouse.x+3;
  int y = mouse.y+3;

  GUI*g = gCursor;  // change gCursor to the scriptname of your GUI

  // make sure new coordinates are within screen limits
  if (x > 320-g.Width) x = 320-g.Width;
  if (y > 240-g.Height) y = 240-g.Height;

  // reposition gui
  g.SetPosition(x, y);


There's room for improvement; e.g. if you cursor is a TheDig style cross, you could move the text to the upper corner in the lower half and left corner in the right half of the screen.
Or you could keep it in one place while the mouse is still over the hotspot.

What you want to keep in mind is that for global behavior like this, you never, ever use functions specific to a single hotspot, like barefoot suggested in his first post.

thanks man but i already found a much simpler way:
1.create an action on the hotspot under-mouse over hotspot
2.create a gui ,with transparant background and border with a lable on it (inside the lable place :"@OVERHOTSPOT@")
3.inside the script of the mouse over hotspot put:
        nameofgui.visible = true;
        nameofgui.setposition(mouse.x+1,mouse.y+1);


thats it.....very simple ;D

Sslaxx

I was thinking about how to do this the other day. The way I'm leaning towards is using two GUIs, maybe transparent, one at the top of the screen and one at the bottom. Hovering over a hotspot would show text on the top GUI, over an object the bottom GUI. The GUIs would only be enabled when the cursor was over an object or hotspot. I shall have to give it a go...
Stuart "Sslaxx" Moore.

Ryan Timothy B

I could be wrong, but using your method Julius
Code: ags
nameofgui.setposition(mouse.x+1,mouse.y+1);

The game can crash if the room isn't scrolling and you move the mouse to the very right or bottom edge. 

Or at least it did for me the other week when I had a GUI following the mouse and it went off the background.  When the GUI left the 'background' it would crash.

Crimson Wizard

#10
Quote from: Ryan Timothy on Tue 29/06/2010 15:54:52
I could be wrong, but using your method Julius
Code: ags
nameofgui.setposition(mouse.x+1,mouse.y+1);

The game can crash if the room isn't scrolling and you move the mouse to the very right or bottom edge.  

Or at least it did for me the other week when I had a GUI following the mouse and it went off the background.  When the GUI left the 'background' it would crash.
This is easily solved by checking if it is beyond the screen border and aligning gui to the left from cursor. But! ofcourse you'll have to calculate text's width first.
If anyone interested, you may check how I did this in my template here:
http://www.box.net/shared/o6l46lnho1

Also, I remember there was more complex template or module for this kind of stuff.... but I forgot its name.

Ryan Timothy B

Well, what I used the GUI to follow the mouse for wasn't text and it had to literally follow the mouse.  All I do is change the visiblity instead of the location if the GUI is off screen.
I posted that just because I figured I'd let the poor guy know that he has a game crashing issue if he leaves it as is.

Khris

Quote from: julius on Tue 29/06/2010 12:41:47
thanks man but i already found a much simpler way:
1.create an action on the hotspot under-mouse over hotspot
2.create a gui ,with transparant background and border with a lable on it (inside the lable place :"@OVERHOTSPOT@")
3.inside the script of the mouse over hotspot put:
        nameofgui.visible = true;
        nameofgui.setposition(mouse.x+1,mouse.y+1);


thats it.....very simple ;D

First of all, please don't quote the entire previous post. The Reply button is beneath the last post, to the right.

Back to the topic now:
Please read again the final sentence of my last post:
QuoteWhat you want to keep in mind is that for global behavior like this, you never, ever use functions specific to a single hotspot, like barefoot suggested in his first post.

The reason is twofold:
-You have to add identical code for every hotspot in the game. This is tedious and more importantly completely unnecessary.
-If you ever were to change the look of it, you'd have to change the code hundreds of times, all over the place.

So, again:
For global behavior like this, you never, ever use functions specific to a single hotspot.

Snarky

There isn't a module or anything for this, is there?

I started out doing essentially this (Khris's method), but I ran into a series of problems. The solution ended up being not particularly simple:

  • First, since the label was sized to be big enough for all hotspot names, its right edge bumped up against the edge of the screen even when the actual text was far away.
  • I tried to set the width of the label dynamically using GetTextWidth(), but then (I think) I could no longer use the "@OVERHOTSPOT@" tag; I had to determine the actual content of the label by scripting.
  • I wanted the text to wrap to another line above a certain length, so I set that as the max width. But when it wraps, the actual length of the line becomes shorter, so again it left space against the right edge.
  • I tried reducing the width pixel by pixel until it GetTextHeight() increased, meaning it had been forced to wrap onto another line. This gave the tightest possible fit, but if the longest line consisted of a single word, that word got broken up in the middle
  • In the end I wrote a function to split a string into its individual words, applied it to the hotspot label text, measured the length of each individual word and made sure the width was not shorter than the longest word.

Finally, this worked. But it's a lot of code for something that started out so simple. That's why I was wondering if anyone's made a module or anything to make it easier.

hedgefield

Quote from: Snarky on Sun 18/09/2011 09:31:12
There isn't a module or anything for this, is there?

There is, actually. A very robust one made by SSH called the Description Module. I'm surprised no one has mentioned it yet.

Snarky

Ah, nice. It doesn't look like it does what I needed, but the idea of setting button fonts to transparent and using that text as the mouseover label is cool, and I'll borrow that.

I also have a bunch of code to highlight the cursor over hotspots, and change to different cursors depending on the value of a custom hotspot/object/character property, and since all of that affects the positioning of the mouseover label, it might in fact be better for me to do all the logic in one place.

Dualnames

There's a more focused module to satisfy your needs. Last time I used it, it was about 4 years ago, and it seemed to work just fine, if you give us more details about that "bunch of code", perhaps we could come up with something.

OverHot Module

A readme is included
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Gilbert

Hmmm. I don't know muchyes about the OverHot module, but because of its age and incompleteness I think it's possibly better to move to SSH's more complete Description module like hedgefield has mentioned.
The OverHot module is even categorised as obsolete in the Wiki and it too recommends using the newer module instead. I also think that the author of OverHot died long time ago already so there's no point to dig up his grave.

Dualnames

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Arjunaz78

i still wondering how to make a custom GUI that can display a current hotspot name when hovering the mouse cursor like Sslaxx told before like Ben Jordan Games,how come?
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

SMF spam blocked by CleanTalk