Mouse Graphic Won't change back to original graphic (using only 1 cursor type)

Started by Phonoitypal, Fri 28/07/2023 23:30:23

Previous topic - Next topic

Phonoitypal

It's me, again, bothering you with a silly question.
I'm making a first person game, and took the advice(which is actually very useful) from another post that one should use only 1 type of cursor.
I have the following code :

Code: ags

function room_AfterFadeIn() {
  Wait(30);
  gBlack1.Visible = false;
  Wait(30);
  gBlack2.Visible =false;
  mouse.UseModeGraphic(eModeInteract);
  Mouse.Mode = eModeInteract;
  mouse.Visible = true;
}



Because I want the cursor to appear after the fade-in. so far so good !

I added the following code to the hotspot, advice taken from some forum post


Code: ags
function hHotspot1_MouseMove()
{
mouse.SaveCursorUntilItLeaves();  
mouse.ChangeModeGraphic(mouse.Mode, 24);
}


The thing is, after moving back the cursor from the hotspot, the same 'changed' graphic persists, not reverting back to its original graphic that I selected(and that it was present before hovering to the hotspot). In the documentation it is written to put the 'savecursoruntillitleaves' think BEFORE the changing - which I did - to actually prevent that from happening. I tried to add the

 "  Mouse.Mode = eModeInteract;
mouse.UseModeGraphic(eModeInteract); 

"
into the global script, but that does not seem to work. also, others 'update' functions relating to the mouse when put into the "global script" again do not work =(.

Can you please provide a more correct code or point me out in the direction of what I'm doing wrong, please ?

Khris

You have changed the graphic, not the mode. For that reason mouse.SaveCursorUntilItLeaves(); has no effect.
To be fair, the function should probably be named mouse.SaveModeUntilItLeaves(); :P

Anyway, to change the cursor over a hotspot, you should implement this behavior globally. Here's one way:

Code: ags
// above repeatedly_execute
LocationType plt;

  // inside repeatedly_execute
  LocationType lt = GetLocationType(mouse.x, mouse.y);
  if (lt != eLocationNothing && plt == eLocationNothing) {
    // mouse moved over active area
    mouse.ChangeModeGraphic(eModeInteract, 24);
  }
  else if (lt == eLocationNothing && plt != eLocationNothing) {
    // mouse left active area
    mouse.ChangeModeGraphic(eModeInteract, 23); // correct sprite slot goes here
  }
  plt = lt;

SMF spam blocked by CleanTalk