@OVERHOTSPOT@, next to the cursor. (SOLVED)

Started by Dan_N, Wed 02/08/2006 17:03:35

Previous topic - Next topic

Dan_N

Hello.

I'm fairly new at this so first of all I ask you, please please don't post directly scripts without explaining then what you meant.

Ok, here's my problem: I've seen it done many times, then name of the hotspot/object/character appearing next to cursor. But not in a text window, so the player has to click for the window to dissapear. To further understand what I mean look at 7 Days a Skeptic and Beneath a Steel Sky.

Is this a too complicated problem to post in the Beginner's Technical Questions?

limeTree

Go to the resource page,i think it is a module,you just upload it and there you go.
Name the objects and otspots when you create them,that name will be shown)

Dan_N

#2
Thanks. I looked it up and found something.
But I don't think I'll implement it any time soon 'cause it looks pretty complicated... ??? and I want to experiment with it...

SSH

It's my Description module, and if you just import it, I think it does what you want.
12

Khris

Quote from: Dan_N_GameZ on Wed 02/08/2006 17:03:35I'm fairly new at this so first of all I ask you, please please don't post directly scripts without explaining then what you meant.
So my guess is you want to learn how to do this rather than a ready-made solution, correct?

One way to do this is using a GUI with a single label.
You'll need mouse.x, mouse.y, GUI.SetPosition and Label.Text.
Look up these commands, if necessary, and try to get it working.

Dan_N

Ok, I think I got an ideea on how to make this happen:

I go to interaction window of a hotspot and at the condition "When mouse over hotspot" I put in an action "Run Script". There at the "mouse.x,mouse.y" coordinates I set the position of a GUI label and write in the label the name of the hotspot. But there something here I'm not getting... Won't the label be refreshed every cycle the mouse is over hotspot? Even if it's not moving?

Khris

Yes, it will. But you won't notice.

Having to put the same code in every hotspot's "when mouse over"-interaction would be horrible.
That's what the repeatedly_execute function in the global script is for (among other things).

The code inside the rep_ex() should basically look something like this:
Code: ags
Ã,  lblHotspotname.Text=Game.GetLocationName(mouse.x, mouse.y);Ã,  // set label text
Ã,  gHotspotname.SetPosition(mouse.x+2, mouse.y+13);Ã,  // move GUI


Alternatively, you could set the label's text to "@OVERHOTSPOT@".

monkey0506

Quote from: KhrisMUC on Thu 03/08/2006 04:50:22
Code: ags
  gHotspotname.SetPosition(mouse.x+2, mouse.y+13);  // move GUI

You'll probably want some sort of bounds-checking on this as well.

Code: ags
  int x = mouse.x, y;
  int width = GetTextWidth(lblHotspotname.Text, lblHotspotname.Font);
  if (mouse.x - (width / 2) < 0) x = 0;
  else if (mouse.x + (width / 2) >= System.ViewportWidth) x = System.ViewportWidth - width;
  /**** THIS WILL ONLY WORK IN AGS 2.72 AND LATER ****/
  mouse.y + (Game.SpriteHeight[mouse.GetModeGraphic(mouse.Mode)] / 2) + 2;
  if (y > System.ViewportHeight) y = mouse.y - GetTextHeight(lblHotspotname.Text, lblHotspotname.Font, width) - (Game.SpriteHeight[mouse.GetModeGraphic(mouse.Mode)] / 2) - 2;
  /******** USE THIS FOR PREVIOUS VERSIONS *********/
  y = mouse.y + 8 + 2;
  if (y > System.ViewportHeight) y = mouse.y - GetTextHeight(lblHotspotname.Text, lblHotspotname.Font, width) - 8 - 2;
  /**********************************************/
  gHotspotname.SetPosition(x, y);


This will ensure that you don't try to display the label outside of the screen (that way you can always see all of the text it contains.

In pre-2.72 versions you will have to either a) code a get mouse-mode graphic function yourself (which will be completely customized toward your game settings), or b) use an arbitrary number to represent 1/2 the height of the mouse (in the above code I used 8 which is half the size of the default cursors).

Dan_N

Hello all, just finihed my omlet... ;) (it was gooood)

Anyway, thought i'd tell you all: i'm using AGS 2.71, and i don't think i'll be upgrading anytime soon, 'cause i got two projects in this AGS already...

And i really don't see why i would want to make a checking to be sure the text isn't displayed outside of the hotspot. if i write in label.text @OVERHOTSPOT@, wouldn't that do the job for me automatically? i think i'm gonna go with krismuc's ideea, 'cause it sounds great and simple and i'm an adept of KISS (keep it simple, stupid! ;)). But thanks for the input and if anybody has anymore ideeas, i'll be glad to hear them!

Ashen

#9
QuoteAnd i really don't see why i would want to make a checking to be sure the text isn't displayed outside of the hotspot.

No, you misunderstood. monkey_05_06's code isn't to stop it being displayed off the HOTSPOT, it's to stop it being displayed off the SCREEN. There's two reasons for this the first being the obvious one of, it's a bit pointless having the hotspot name displayed if half of it isn't actully visible. The other is, if the hotspot is very near the edge of the screen, mouse.x+2 or mouse.y+13 might be outside the screen boundaries - which would cause a crash.
Neither of these might be issues for you, depending on how you set your rooms up - but surely it's simpler to do this than have to fuss with the placement of hotspots in the room (and if you also want it to work on Characters that might be moving about, this'd become even harder).

EDIT: Oops. Fixed attribution, sorry about that, monkey. Somehow managed to read the author of the quote, instead of the post it was in.
I know what you're thinking ... Don't think that.

monkey0506

#10
Quote from: Ashen on Thu 03/08/2006 10:38:00KhrisMUC's code isn't to stop it being displayed off the HOTSPOT, it's to stop it being displayed off the SCREEN.

Erm...monkey_05_06's code you mean? ;)

Anyway, you don't have to use the bounds-checking. I just figured it could save you some trouble if you want to be able to have hotspots near the edge of the screen...because like Ashen said, it will cause problems if you're not careful with where you try to position the GUI.

[EDIT:]

Ashen, it's okay. :=

Dan_N

Yeah, well, I like to keep my rooms small, in the center, with lots of black arround and some space to the end of the screen. Also, the GUIs i like to make for displaying of scoring, buttons whatever are always visible and near the end of the screen, so I don't know what good the bounds checking will do. But again, input is good and I thank you for that.

SMF spam blocked by CleanTalk