Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Nixxon on Sun 20/05/2012 23:58:18

Title: Mouse x,y pos on scrolling background
Post by: Nixxon on Sun 20/05/2012 23:58:18
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
Title: Re: Mouse x,y pos on scrolling background
Post by: Ryan Timothy B on Mon 21/05/2012 00:19:44
Code (ags) Select
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) Select
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.
Title: Re: Mouse x,y pos on scrolling background
Post by: Nixxon on Mon 21/05/2012 00:22:46
Badass dude, I'll give those a go when I get home.
Title: Re: Mouse x,y pos on scrolling background
Post by: monkey0506 on Mon 21/05/2012 00:51:48
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.