Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: johanvepa on Mon 05/10/2015 20:42:04

Title: Solved: Mouse moves over hotspot - how to reset!
Post by: johanvepa on Mon 05/10/2015 20:42:04
I'm toying with the idea of adding a feature to my pet project.

It's Sierra-style, but instead of the usual walk-look-use-talk icons rotating by right click, I'd like to make the cursor change into the appropriate mouse.Mode when the mouse is moved onto a select hotspot.

This is very easy using the "Mouse moves over hotspot" event for a hotspot. Then, using the "Any click on hotspot" event, I can execute a command that's appropriate for the particular hotspot.

However, this only works one way. The mouse moves over the hotspot and the cursor changes. I'd like the cursor to change back to default once the mouse moves away from the hotspot again.

I have the feeling this might be accomplished easily using and "if" in repeatedly_execute and mouse.UseDefaultGraphic, but I need to tell the script what event to look for, i.e. something like this in the main script:

Code (ags) Select

function repeatedly_execute()
{
    if (OnTheEventOfTheMouseLeavingAHotspot)
  {
  mouse.UseDefaultGraphic;
  }
}


Now, typing OnTheEventOfTheMouseLeavingAHotspot is rather silly of course, but what should I type in its stead?

Title: Re: Mouse moves over hotspot - how to reset!
Post by: Slasher on Tue 06/10/2015 04:07:35
Use the Hotspot.GetAtScreenXY(..) function

Code (ags) Select

if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[1]) {
  //Change cursor graphic for Hotspot 1
}
else if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[2]) {
  //Change cursor graphic for Hotspot 2
}
//Etc for other hotspots
else {
  //Set default cursor graphic for No Hotspot
}


also check out: http://www.adventuregamestudio.co.uk/forums/index.php?topic=25645.msg323172#msg323172




Title: Re: Mouse moves over hotspot - how to reset!
Post by: johanvepa on Tue 06/10/2015 14:23:32
If this is put into repeatedly_execute, won't it give performance issues, like a blinking mouse cursor, when the mouse mode updates 40 times a second?

Title: Re: Mouse moves over hotspot - how to reset!
Post by: Slasher on Tue 06/10/2015 15:27:59
Why don't you just try it?

Quotewhen the mouse mode updates 40 times a second?
at 40 times a second you'de never notice (faster than the eye) ;)
Title: Re: Mouse moves over hotspot - how to reset!
Post by: Crimson Wizard on Tue 06/10/2015 15:48:12
I think it should not redraw cursor if the graphic is the same.
Title: Re: Mouse moves over hotspot - how to reset!
Post by: johanvepa on Tue 06/10/2015 17:18:49
Quote from: Crimson Wizard on Tue 06/10/2015 15:48:12
I think it should not redraw cursor if the graphic is the same.

That's sort of what I thought. Why redraw 40 times a second?
But then again, Slasher is right, I didn't try it yet (stuck at the office and too eager to wait until I get home :grin:)
Title: Re: Mouse moves over hotspot - how to reset!
Post by: Snarky on Tue 06/10/2015 17:46:10
Quote from: slasher on Tue 06/10/2015 15:27:59
Why don't you just try it?

Quotewhen the mouse mode updates 40 times a second?
at 40 times a second you'de never notice (faster than the eye) ;)

This is not true. If the cursor were to change shape (or disappear) for one frame, it would certainly be noticeable at 40 fps, unless the change was very subtle. You'd probably see it as a brief flicker.
Title: Re: Mouse moves over hotspot - how to reset!
Post by: johanvepa on Tue 06/10/2015 18:12:06
Then again, perhaps I could simply use an "if" statement to determine if the cursor is still on the hotspot, and only "if" this is no longer true should it return to default. I'll try it out.

Title: Re: Mouse moves over hotspot - how to reset!
Post by: johanvepa on Tue 06/10/2015 20:29:26
Tested and working. Thank you slasher  ;)




function room_RepExec()
{

  if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hotspot[1])
  {
    if (mouse.Mode != eModeLookat)
    {
      mouse.Mode = eModeLookat;
    }
  }
  else if (mouse.Mode != eModeWalkto)
  {
    mouse.Mode = eModeWalkto;
  }   

}
Title: Re: SOLVED: Mouse moves over hotspot - how to reset!
Post by: Khris on Wed 07/10/2015 01:05:54
To change the cursor for *all* hotspots: http://www.adventuregamestudio.co.uk/forums/index.php?topic=52667.msg636520746#msg636520746
Title: Re: SOLVED: Mouse moves over hotspot - how to reset!
Post by: johanvepa on Wed 07/10/2015 19:51:48
Thank you for that too, Khris. I was wondering how to avoid clashes with active inventory items, your solution will solve that.

But another idea popped up: Can I use custom properties of hotspots to determine which cursor should be applicable to that hotspot? The ideal result would be to have one hotspot, with custom property "1", activate the eye cursor, and another hotspot, with custom property "2", activate the hand cursor. In order to make this work on game level, I figure I would have to use properties. But I lack for the words to put into AGS to let it know whe're looking for properties.

Let's say I make a custom property called CursorProperty (number type). And then something along the lines of:
Code (ags) Select

if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == "HotspotHasProperty1")
    {
      mouse.Mode = eModeLookat;
    }
else if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == "HotspotHasProperty2")
    {
      mouse.Mode = eModeInteract;
    }


Title: Re: Mouse moves over hotspot - how to reset!
Post by: Snarky on Wed 07/10/2015 21:02:40
Yes, your thinking is more or less right, that's how you'd want to do it. You wouldn't have different properties for each hotspot, though. Rather, you'd have one property with different VALUES depending on which cursor you want.

The AGS syntax for this looks something like:

Code (ags) Select
// Here's how you get the "Cursor" property of the current hotspot
Hotspot* activeHotspot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
int hotspotCursor = -1;
if(activeHotspot != null)
  hotspotCursor = activeHotspot.GetProperty("Cursor");

// And here's how you use it to set the cursor
if(hotspotCursor == 1)
  mouse.Mode = eModeLookAt;
else if(hotspotCursor == 2)
  mouse.Mode = eModeInteract;
// etc.
Title: Re: Mouse moves over hotspot - how to reset!
Post by: johanvepa on Wed 07/10/2015 21:10:41
Wait, sorry for taking your time all, I think what I'm looking for is included in IsInteractionAvailable, which I've just found out about. I'll have to check it out and see if it works as well as I suspect  ;)

And thank you, Snarky, for your quick and helpful reply.
Title: Re: Mouse moves over hotspot - how to reset!
Post by: johanvepa on Wed 07/10/2015 21:17:45
This works a treat   :)
At the time only for LookAt, but it should be easy to extend to other interactions. Also, I have a bit of trouble with my inventory items, I'll have to figure out a way to "turn it off" when viewing inventory, but that should be a piece of cake.

And so simple. I like simple   :)

Code (ags) Select

  if (IsInteractionAvailable(mouse.x,mouse.y, eModeLookat) == 1)
  {
    if (mouse.Mode != eModeLookat)
    {
      mouse.Mode = eModeLookat;
    }
  }
  else if (mouse.Mode != eModeWalkto)
  {
    mouse.Mode = eModeWalkto;
  }   
Title: Re: Solved: Mouse moves over hotspot - how to reset!
Post by: Khris on Tue 13/10/2015 00:52:29
There's no need to compare boolean return values to 1, you can remove "== 1" and it will still work, since IsInteractionAvailabe() already returns "true" or "false" which "true == 1" and "false == 1" will evaluate to anyway.
Title: Re: Solved: Mouse moves over hotspot - how to reset!
Post by: johanvepa on Tue 13/10/2015 08:39:13
But the manual says to use "== 1" and here I went and thought I had it   :~(


I shouldn't go and read such stuff :-\





(Just kidding, thank you for this point, Khris)