How to highlight individual object with mouse over?

Started by isatche, Wed 22/07/2020 16:51:19

Previous topic - Next topic

isatche

Hi,

I would like to highlight object when the mouse is over it.
I tried it by setting hotspot over the object and when the mouse is over the object lights up but when I remove the mouse it stays lit.
How do I make it lit only while the mouse is over it?

On the same note, I would like the door to open for example when the character stands on a plate (hotspot) and close when the caracter walks away. I think the script should be almost the same.

Code: ags

function hNew_MouseMove()
{  oNew.Graphic = 55;}


Thank you :)

Khris

Do you need this in all rooms? Or just one? How do you want to highlight the object? A second sprite? An outline? Tinting?

For the door, use a Region and its "player walks onto" and "player walk off" events.

isatche

Hi Khris,
I want it for the menu on mouse over, plus I was thinking of mechanics where I can use some device (in game) to highlight certain buttons on mouse over to be used in puzzle.
I will highlight an object by using second sprite. The way I started in my code is good enough I think, I just need to switch the graphic back to not-highlited when the cursor is removed from the hotspot.
Thank you.

Khris

For the menu I'd use a GUI; it has buttons which natively support mouseover images.

Still, regarding objects, the basic idea is to track the object below the mouse in repeatedly_execute:
Code: ags
Object* prevObj;

function room_RepExec() {
  Object* currObj = Object.GetAtScreenXY(mouse.x, mouse.y);

  if (currObj != prevObj) {
    if (prevObj != null) {
      // mouse moved away from prevObj
      prevObj.Graphic = original_slot[prevObj.ID];  // auto-populated array storing original graphics
    }
    if (currObj != null) {
      // mouse moved over currObj
      currObj.Graphic = currObj.GetProperty("active"); // custom int property storing mouseover slot
    }
  }
  prevObj = currObj;
}


SMF spam blocked by CleanTalk