Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: millennium2k on Tue 24/12/2013 23:04:38

Title: Change graphic mouse cursor [Solved]
Post by: millennium2k on Tue 24/12/2013 23:04:38
Hi,
I'm developing a first person adventure game and I want change the graphic mouse cursor on an hotspot hover event.
How can I do it?
I tried with this code but nothing happens:

Code (ags) Select

// room script file

function hDoorBedroomHall_MouseMove()
{
Mouse.ChangeModeGraphic(eModeLeft, 12); //12 is the ID cursor
}

function hDoorBedroomHall_AnyClick()
{
cChecco.ChangeRoom(3);
}


Many thanks.

Title: Re: Change graphic mouse cursor
Post by: AprilSkies on Wed 25/12/2013 10:38:02
Ciao millennium,

I think it won't work that way.

You should do something like that:

Suppose you have some mouse cursors called: eModeLeft, eModeRight, eModeForw, eModeLook, eModeInteract, eModeDefault
(it's only an example)
And suppose you have in your room 3 hotspot (hHOT1, hHOT2, hHOT3), 1 object (oOBJ1), 1 character (cGIOVANNI)
(it's only an example)

create a REPEAT EXECUTE in your room :

Code (ags) Select
function room_RepExec()
{
    if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[0] && Object.GetAtScreenXY(mouse.x, mouse.y) == null && Character.GetAtScreenXY(mouse.x, mouse.y) == null)
     {
     mouse.UseModeGraphic(eModeDefault);
     mouse.Mode = eModeDefault;
     }
     else
     {
     if (Character.GetAtScreenXY(mouse.x, mouse.y) == cGIOVANNI) {mouse.UseModeGraphic(eModeLook); mouse.Mode = eModeLook;}
     if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hHOT1) {mouse.UseModeGraphic(eModeLeft); mouse.Mode = eModeLeft;}
     if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hHOT2) {mouse.UseModeGraphic(eModeRight); mouse.Mode = eModeRight;}
     if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hHOT3) {mouse.UseModeGraphic(eModeForw); mouse.Mode = eModeForw;}
     if (Object.GetAtScreenXY(mouse.x, mouse.y) == oOBJ1) {mouse.UseModeGraphic(eModeInteract); mouse.Mode = eModeInteract;}
     // add other if ... here
     }
}


REPEAT THAT THING in EACH ROOM (with its ojects hotspots, etc.)

then... to make something appening on mouse click just create the function ANYCLICK
for example:

Code (ags) Select
function hHOT1_AnyClick()
{
cChecco.ChangeRoom(3);
}
Title: Re: Change graphic mouse cursor
Post by: Khris on Wed 25/12/2013 11:20:39
Doing this on a per room and per hotspot basis is the absolute last resort.

What you probably need is GetLocationType:

Code (ags) Select
// in GlobalScript.asc
int old_lt;

function repeatedly_execute()  // this function is already there
{
  int lt = GetLocationType(mouse.x, mouse.y);
  if (lt != old_lt) {
    if (lt == eLocationHotspot) {
      // mouse just moved over a hotspot
      Hotspot *h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
      ...
    }
  }
  old_lt = lt;

  ...  // other content
}


You can now change the mouse cursor graphic/mode to a generic one, but you can also use for instance a custom property to use an arrow pointing in a certain direction, or other stuff.
To do this, you have to add a suitable custom property to hotspots (look it up in the manual), then use something like:
Code (ags) Select
      int property = h.GetProperty("cursor");
      if (property == 1) mouse.ChangeModeGraphic(eModeInteract, NORTH_ARROW);  // actual slot # here
Title: Re: Change graphic mouse cursor
Post by: millennium2k on Wed 25/12/2013 20:54:28

Hello guys, thanks for the answers but both solutions does not work.

@Khris, this code is not clear:


Hotspot *h = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
      ...


Thanks.
Title: Re: Change graphic mouse cursor [Solved]
Post by: millennium2k on Wed 25/12/2013 22:19:48
Solved. It's really easy.

Code (ags) Select

function hDoorBedroomHall_MouseMove()
{
mouse.SaveCursorUntilItLeaves();
mouse.Mode = eModeLeft;
}

function hDoorBedroomHall_AnyClick()
{
cChecco.ChangeRoom(3);
}