I'm following this idea:
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!
Now, this is okay, but this assumes you'll have every item appear in a fixed place *I THINK*. I'm not sure entirely, and I'm not sure if this is the best practice for building an array for an adventure game inventory system, but this example does work, I'm just not *QUITE* sure how to, say, push the array to the right to add the new item to the start, similarly, a cell would need to be removed if an object was used. Can anyone just clarify these couple of points and if this is the best way of building the inventory?
EDIT: Yes, I've just made sure I INSERT the item in the array:
Now, I'll need to figure out how to grab the correct cell for destroying it from the array when it's used/given awayetc.