Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Chim on Wed 13/10/2010 14:06:17

Title: Detecting the object on which mouse is over. *SOLVED*
Post by: Chim on Wed 13/10/2010 14:06:17
Hello AGS community,

I would to know if there is a simple function in AGS which would return the object on which mouse is over, be it a Hotspot, a character, an object or nothing at all.

Otherwise, It would be possible to do it by checking the current mouse position and the position of every object in room... but well, that would be less neat.

Thank you very much !
Title: Re: Detecting the object on which mouse is over.
Post by: Khris on Wed 13/10/2010 14:15:00
I usually do it like this:

  int mx = mouse.x, my = mouse.y;
  int lt = GetLocationType(mx, my);

  // object?
  Object*o;
  if (lt == eLocationObject) {
    o = Object.GetAtScreenXY(mx, my);
    ...
  }

  // etc.


There are also GetAtScreenXY functions for InventoryItems, Characters, Hotspots. For regions, there's GetAtRoomXY().

If you just need the name, there's
  String s = Game.GetLocationName(mouse.x, mouse.y);
  CursorLabel.Text = s;  // put name on text following the mouse
Title: Re: Detecting the object on which mouse is over.
Post by: Chim on Wed 13/10/2010 14:29:28
Thanks a lot, that's exactly what I was looking for.

I had not found yet the eLocationType to compare to !