—
Hey Joel, here are some of the key things that helped me build an efficient inventory with an array.
Create only one sprite for the inventory items, this sprite should have a different animation for every item in the inventory with an appropriate name. Let's say that you have 8 visible slots in your inventory. At the start of each scene create 8 instances of the inventory item, even if you're inventory is bigger than 8 slots, it's only about the visible slots. Position each of these items in the appropriate place, I create an image point in the inventory bar animation and set each sprite to that position e.g: create object 'invitem' on layer GUI at 'InventoryBar.ImagePointX"item1" etc. etc. Then run a function that fills the items to correspond with the array. Here's mine:
So this first sets a variable stored in my inventory array to 0, then for each instance of my inventory item sprite it sets the animation to whatever is in the array at the value of this variable. For example if the value saved into my array's X at 0 is "Hat" it will set the animation to "Hat". Just make sure you've create an animation called "Hat" and it will work. Then it adds 1 to the variable, so the second time it runs this loop it will set the animation to whatever is in the array's X at 1. If the value is 0 this means the slot is empty and it sets the animation to default, i.e. an empty picture.
Moving the inventory left and right isn't too difficult. You create a variable, lets call it invScroll, and you add 1 to this variable when the left key is pressed and subtract 1 when the right key is pressed. You also run a function after changing the value of invScroll, i.e. every time you press left or right. This function is almost identical to the one above for arranging the inventory, except instead of: set animation to Inventory.At(Inventory.item) it will be set animation to Inventory.At(Inventory.item+invScroll)
Hopefully that makes sense and is enough to get you started!