SOLVED: Changing Inventory graphic while that item is selected

Started by TurduckenMan, Thu 01/10/2015 22:56:22

Previous topic - Next topic

TurduckenMan

Hello everyone! Quick question from me, I'm currently trying to make it so that when the player has clicked an item in their inventory, the graphic is swapped to a "greyed out" version.

I'm mostly curious how you guys go about doing this? I'm aware of the InventoryItem.graphic feature, but it's more so the overarching system than doing it on a single case basis that I'm stuck with. By this I mean that I'm unsure as to whether or not there's a simple way to swap all of my inventory items graphics with a function or two, or if I have to manually code the change for every possible item.

Is there a way I can associate a graphic with another graphic? Because currently the only thing I can think to do is to say "If X is equipped, change X graphic to Y; if Z is equipped, change Z graphic to A" etc etc and it just seems totally unrealistic based on how many items there are in my game. I feel like there's a way I could say "If an item is equipped, change its graphic to the associated greyout graphic" but my inexperience with coding is making it hard for me to find a solution.

Sorry if that comes across as confusing at all, hopefully you sort of understand what I'm trying to do.
Any help is much appreciated!

Mandle

There's probably a coding solution, but what I would simply try to do is organise the sprites list so that all the normal inventory sprites and all the special sprites are arranged in the same order in two seperate block groups. That way you can just say "If X is equipped, change X graphic to X graphic+100" (or however far apart the two groups are on the list.)

However: If you just want to change the colour of the image then maybe take a look at the tint command. This could also save you a lot of unneeded sprites...

TurduckenMan

#2
Hey, thanks a lot for the response!

Me and my friend were actually thinking about just adding 100 but it didn't feel right haha. Also, I don't really know how to change the numbers for my sprites without just reimporting them all, so we weren't sure it would work too well.

Fortunately, I got it to work using a semi-interesting method, and it seems to be working very well so far! I'll post what I did here just in case anyone else ever wants to try it out.

In the Properties Schema, I created two properties that could only apply to inventory items. I named them "ColouredID" and "GreyedID". For each inventory item, I assigned the ColouredID as the sprite number for the item's sprite, and I assigned GreyedID as the greyed out sprite's number. Then, in "repeatedly_execute" I just put this code:

Code: ags

function UpdateInventoryIcons () {
  if (player.ActiveInventory != null) {
    player.ActiveInventory.Graphic = player.ActiveInventory.GetProperty ("GreyedID");
  } else {
    if (lastItem != null) {
      lastItem.Graphic = lastItem.GetProperty ("ColouredID");
    }
  }
}


"lastItem" is just an InventoryItem I declared at the top, which I assign the player's active inventory to whenever they useInv or dismiss their inventory. Funny, never thought the properties would come up for me but now I'm thinking of all kinds of ways I can use them!

Thanks again for the response, much appreciated!

Mandle


Snarky

You worked out the coding solution to switch graphics on your own. I just wanted to mention that if your inventory item sprites are relatively small, it might be possible to generate the grayed-out versions on the fly using DynamicSprites and DrawingSurfaces. (The AGS calls you'd need are pretty slow, but on newer computers with small sprites it might work.)

SMF spam blocked by CleanTalk