Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Mon 09/01/2012 16:23:24

Title: Item Cursor Animation Over Hotspots[SOLVED]
Post by: on Mon 09/01/2012 16:23:24
Is it possible to animate an ITEM's(inventory) cursor on hotspots like it's done in "The Dig"?

If it is, try to explain me how.*
(or maybe there exists a module for it or plugin or something idk)

*or show me code how to script it

Thanks!
Title: Re: Item Cursor Animation Over Hotspots
Post by: on Mon 09/01/2012 16:54:01
Not right out of the box, but since you can easily test if the mouse is over something AND you can change the mouse cursor's sprite at will, I don't think it's impossible.

I would do it by checking if an inventory item is currently selected, then checking if the mouse is over a hotspot, and then change the sprites manually at a timed interval, depending on which item is selected.
Even as I type this I realise that it sounds a bit complicated- I bet there's a simpler solution.
Title: Re: Item Cursor Animation Over Hotspots
Post by: on Mon 09/01/2012 17:13:11
Quote from: Ghost on Mon 09/01/2012 16:54:01
Not right out of the box, but since you can easily test if the mouse is over something AND you can change the mouse cursor's sprite at will, I don't think it's impossible.

I would do it by checking if an inventory item is currently selected, then checking if the mouse is over a hotspot, and then change the sprites manually at a timed interval, depending on which item is selected.
Even as I type this I realise that it sounds a bit complicated- I bet there's a simpler solution.

I hope so.. ^^

Anyway thanks for the fast answer. I might manage to do it myself.
Perhaps if I did as you said for every item in global script(repeatedly execute function) something like this:

  if (player.ActiveInventory = iItem1) {
    mouse.Mode = eModeItem1;
  }
  else
  {}
}

Which means that I will have to make a special cursor for every item.
Title: Re: Item Cursor Animation Over Hotspots
Post by: on Mon 09/01/2012 17:19:23
Quote from: Bogdan on Mon 09/01/2012 17:13:11
Which means that I will have to make a special cursor for every item.

I wouln't do that, keep the UseInvOn cursor mode so that AGS can handle inventory interaction for you automatically. Create a set of views, one for each item, and write yourself a function that checks which item is currently held by the player. Then you can, in repeatedly execute, include a function that assigns the sprites to you.

Sorry for the shoddy description, but if you really need this and can bear with my approach, I'll see if I can write an actual code example.
Title: Re: Item Cursor Animation Over Hotspots
Post by: on Mon 09/01/2012 17:46:56

   if ((GetLocationType(mouse.x, mouse.y) != eLocationNothing)) {
     
     if (player.ActiveInventory == iHammer) {
    iHammer.CursorGraphic = 104;
  }
  else
  {   
    }
}
      if ((GetLocationType(mouse.x, mouse.y) == eLocationNothing)) {       
     if (player.ActiveInventory == iHammer) {         
      iHammer.CursorGraphic = 92;
    }
      }

All that I needed is that item's cursor changes it's appearance(e.g. outlines of the sprite change color). And with your help, I managed to do something in the Global Script (repeatedly execute function). I didn't know for that I can actually change sprite of this cursor that easy by just typing in the sprite number. And the crosshair that is drawn by AGS actually exists in the new cursor graphic. :o Really interesting things. Thanks again.
Title: Re: Item Cursor Animation Over Hotspots[SOLVED]
Post by: on Mon 09/01/2012 18:21:49
No worries- I thought there would have to be an actual animation! Yeah, you're all set up now!

- if you find character speech or blocking animations messing up your system, by the way, just move the checks to repeatedly_execute_always!
Title: Re: Item Cursor Animation Over Hotspots[SOLVED]
Post by: Khris on Mon 09/01/2012 19:21:33
That code is bad, sorry. It might work but you can do it a lot easier.

// above game_start
int InvItemCursorSlot[];

// in game_start, store all default slots

  InvItemCursorSlot = new int[Game.InventoryItemCount + 1];
  int i = 1;
  while (i <= Game.InventoryItemCount) {
    InvItemCursorSlot[i] = inventory[i].CursorGraphic;
    i++;
  }

// in rep_exe

  if (mouse.Mode = eModeUseinv) {
    InventoryItem*ai = player.ActiveInventory;
    if (GetLocationType(mouse.x, mouse.y) != eLocationNothing) ai.CursorGraphic = InvItemCursorSlot[ai.ID] + 50;
    else ai.CursorGraphic = InvItemCursorSlot[ai.ID];
  }


Now reassign the sprite slot numbers of the outlined items so that each is original sprite slot + 50.
Or use a bigger interval if some of the sprite slots are occupied.

Still annoying but a lot faster and cleaner than copy-pasting that block of code dozens of times.
Title: Re: Item Cursor Animation Over Hotspots[SOLVED]
Post by: on Mon 09/01/2012 19:39:58
Quote from: Khris on Mon 09/01/2012 19:21:33
That code is bad, sorry. It might work but you can do it a lot easier.

// above game_start
int InvItemCursorSlot[];

// in game_start, store all default slots

  InvItemCursorSlot = new int[Game.InventoryItemCount + 1];
  int i = 1;
  while (i <= Game.InventoryItemCount) {
    InvItemCursorSlot[i] = inventory[i].CursorGraphic;
    i++;
  }

// in rep_exe

  if (mouse.Mode = eModeUseinv) {
    InventoryItem*ai = player.ActiveInventory;
    if (GetLocationType(mouse.x, mouse.y) != eLocationNothing) ai.CursorGraphic = InvItemCursorSlot[ai.ID] + 50;
    else ai.CursorGraphic = InvItemCursorSlot[ai.ID];
  }


Now reassign the sprite slot numbers of the outlined items so that each is original sprite slot + 50.
Or use a bigger interval if some of the sprite slots are occupied.

Still annoying but a lot faster and cleaner than copy-pasting that block of code dozens of times.

W :o w thanks Khris!
My code worked well since I have just tested it, but your seems so much more practical and professional. It makes things a lot easier. :D
Title: Re: Item Cursor Animation Over Hotspots[SOLVED]
Post by: Khris on Mon 09/01/2012 22:57:01
Btw, I've just noticed that you don't really need the first part, provided the interval is great enough.

Say your original sprites have slots within 70 to 130, then you could put the outlined ones in 170 to 230 and simply check if the slot is > 150 and subtract 100 if it is/add 100 if it isn't. So no need to store the default sprites first any longer.
Title: Re: Item Cursor Animation Over Hotspots[SOLVED]
Post by: on Mon 09/01/2012 23:02:29
Quote from: Khris on Mon 09/01/2012 19:21:33
That code is bad, sorry. It might work but you can do it a lot easier.
I was secretly hoping for you to turn up here and save the day- I knew there'd be something easier.  ;)