Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ewen on Tue 10/06/2025 23:30:43

Title: Specific Cursors for Different Objects
Post by: Ewen on Tue 10/06/2025 23:30:43
Hello!

I'm an amateur AGS user but have spent quite a lot of time developing a children's game with custom GUIs and a 'left click only' interface where specific animated cursor icons are displayed when hovering over interactable things. This is really easy to do with hotspots but I was hoping someone might be kind enough to answer the following question:

Is there a way to have different cursors activate when specific objects are hovered over? E.g. a door object should have an animated cog but an item object should have a 'pick up' animated icon.

I've spent a lot of time on this and, so far, have found some solutions but none are doing exactly as I want. For example, via the global script, I could make ALL objects have the same custom cursor instead of specific cursors for different objects.

I'm tempted to revert to a more standard verb coin template but I'm delighted that I've managed to do some pretty complex things so far and I'm not quite ready to give up on the current direction of the game.

Thank you!
Title: Re: Specific Cursors for Different Objects
Post by: Laura Hunt on Wed 11/06/2025 08:53:57
Check out custom properties (https://adventuregamestudio.github.io/ags-manual/CustomProperties.html).
Title: Re: Specific Cursors for Different Objects
Post by: Khris on Wed 11/06/2025 11:15:06
I assume you're using the "mouse moves over hotspot" event?

Anyway, like Laura says, use a custom property. I'd get rid of all the existing hotspot events and just implement this globally.
The cursor modes all have enum/int values, so you can use these to set it up. eModeInteract for instance is 2.

So I'd add a custom property "cursor_mode" like this:
(https://i.imgur.com/QrDbK8k.png)
(or skip characters here if you're always showing a talkto cursor)

Next you need to track what's under the cursor to implement your own "moves over" and "leaves" events:
// above rep_exe
LocationType prevLocation;
Hotspot* prevH;
Object* prevO;
Character* prevC;

void HandleCursors() {
  int mx = mouse.x, my = mouse.y;
  Hotspot* currH = Hotspot.GetAtScreenXY(mx, my);
  Object* currO = Object.GetAtScreenXY(mx, my);
  Character* currC = Character.GetAtScreenXY(mx, my);
  LocationType currLocation = GetLocationType(mx, my);
  bool isH = currLocation == eLocationHotspot, isO = currLocation == eLocationObject, isC = currLocation == eLocationCharacter;
  bool typeChange = currLocation != prevLocation;

  CursorMode newMode = eModeWalkto;
  if (isH && (typeChange || currH != prevH)) newMode = currH.GetProperty("cursor_mode");
  else if (isO && (typeChange || currO != prevO)) newMode = currO.GetProperty("cursor_mode");
  else if (isC && (typeChange || currC != prevC)) newMode = eModeTalkto;
 
  if (newMode != mouse.Mode) mouse.Mode = newMode;
  prevH = currH;
  prevO = currO;
  prevC = currC;
}

  // inside rep_exe
  HandleCursors();

If most of your objects are supposed to show a pick up cursor instead, create two separate properties and use the 2nd one for objects with a default value of 5. This also requires changing the GetProperty string in the object line above.
Title: Re: Specific Cursors for Different Objects
Post by: Ewen on Wed 11/06/2025 13:21:43
Thank you. I really appreciate both of you getting back to me and this all seems super helpful. I look forward to jumping into this and it seems doable. Thanks again for taking the time to get back to me.
Title: Re: Specific Cursors for Different Objects
Post by: Crimson Wizard on Wed 11/06/2025 14:39:31
I believe that this topic is one of the best candidates for a dedicated tutorial in the manual, along with the custom speech, repeatedly moving NPCs, and similar tasks.
Title: Re: Specific Cursors for Different Objects
Post by: Ewen on Wed 11/06/2025 20:26:49
Hi Khris, I used this exact code and and solved the main issue and I'm able to understand how to change cursors over objects etc now using custom properties. Thank you so much for this.

However, one slight issue is that cursor is no longer changing when inventory items are selected. Do you have any thoughts on this? When I delete the code, the cursor works as normal on inventory items again.

EDIT: In addition, when I use an inventory item (which still has the interact cursor) on an object, the cursor changes to that of the object.

Any help on this would be greatly appreciated. Thank you.
Title: Re: Specific Cursors for Different Objects
Post by: Khris on Wed 11/06/2025 23:59:45
Fixing this might be as simple as
  // rep_exe
  if (player.ActiveInventory == null) HandleCursors();

In other words, if the player has picked an inventory item, skip the automatic cursor mode change.

However, your problem description seems to contradict that, so I'm not sure how to address this.
Title: Re: Specific Cursors for Different Objects
Post by: Ewen on Thu 12/06/2025 01:23:07
Believe it or not, this worked and all the issues are resolved! Thank you. You've saved me a whole lot of work.