Mouse x,y pos on scrolling background

Started by Nixxon, Sun 20/05/2012 23:58:18

Previous topic - Next topic

Nixxon

Before I start, I spent a good part of last night hunting for a solution to this. Most of the old threads I dug up didn't seem relevant.

Though it would seem to me like a pretty common query. Appreciated in advance.

I'd like to my mouse cursor to change mode whilst it's hovering over a GUI that is 'always on'. (I have the code for this, too easy).

To implement it...

I can run a repeatedly execute to do this for a mouse x, y pos. However quite a few of my backgrounds are scrolling, so the X co'ord changes :(

I've also tried drawing a hotspot on the room and have the cursor change whilst over the hotspot. Once again, doesn't work properly with a scrolling background.

I know I'm missing something incredibly simple here.


Cheers,

Nick

Ryan Timothy B

Code: ags
function repeatedly_execute_always() {
  GUI *theGui = GUI.GetAtScreenXY(mouse.x, mouse.y);
  if (theGui == gYourGUI) {   //make sure  gYourGUI  reflects the name of your GUI
    mouse.Mode = eModePointer;  // or whatever mode you wanted
  }
}


Or if you wanted a more hard coded coordinates approach:
Code: ags
function repeatedly_execute_always() {
  if (gYourGUI.Visible 
      && mouse.x > gYourGUI.X && mouse.x < gYourGUI.X + gYourGUI.Width 
      && mouse.y > gYourGUI.Y && mouse.y < gYourGUI.Y + gYourGUI.Height) {   
    mouse.Mode = eModePointer;  // or whatever mode you wanted
  }
}


Multiple approaches. Enjoy.

Nixxon

Badass dude, I'll give those a go when I get home.

monkey0506

As implied by GetAtScreenXY, that function always works with screen coordinates, even if the room is a scrolling one.

GUIs are always positioned by screen coordinates, not room coordinates.

The mouse position is always in screen coordinates.

What's the problem? Character, Object, and Hotspot positions can be in room coordinates, in which case you may need to offset by GetViewportX/GetViewportY to get the screen coordinates, but everything you stated is already screen coordinates.

SMF spam blocked by CleanTalk