inventory

Get help using Construct 2

Post » Fri Mar 01, 2013 3:00 pm

Hi all,

I'm using an 2d array to store weather the user has aquired an item or not "none" being not aquired and it bieing changed to "sword","shield" as you pick them up.

Im trying to create an inventory zelda style, as you pick up items they are stored in the 1st available slot on a 4x6 grid like below.


Anyone have any ideas how i would achieve this?

thanks

image

B
14
S
4
G
3
Posts: 77
Reputation: 4,011

Post » Fri Mar 01, 2013 4:24 pm

My first tactic would be to make the sprite for the square of inventory have an animation for each possible inventory item. The animations would be named exactly like the array stores the values, and then on change of the array set the animation of each sprite instance x,y to array[x,y]. (maybe have to cast array[x,y] as a str, I dunno offhand)
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Fri Mar 01, 2013 4:58 pm

I would create a function to show the items in the array, and call it as needed. I'm not at my main computer, so I'll just wing it with the code. I'm assuming you're storing the inventory items in an array that is 4x6x1. If so, it would be something like this:

On Function "Show Inventory"
      For Each InventoryArray XY
            Create Object IventoryItem
            Set InventoryItem Animation to InventoryArray.CurValue
            Set InventoryItem X position to (Whatever X you want the first inventory item to appear + InventoryArray.curX * InventoryItem.Width)
            Set InventoryItem Y position to (whatever Y you want the first inventory item to appear. + InventoryArray.curY * InventoryItem.Height)
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Fri Mar 01, 2013 5:07 pm

I'm a lot lazier, so I would probably build the inventory as a container in the layout editor, and then only programmatically set the sprites for the items (as zatyaka and I both said), and control visibility of the container to show/hide the inventory, as opposed to rebuilding it via a function.

I'm unsure whether or not you could get away with changing the inventory slot "animation" on item acquisition only, or if you should check the values every time you open the inventory, but it would probably be safest to recheck them every time the inventory is opened, especially if you expect the inventory to change a lot (e.g. droping items, drinking potions and the like.)
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Tue Mar 05, 2013 10:57 am

Thanks for the help guys, I went with cincipons idea which was similar to my own. Now my inventory works fine :)
B
14
S
4
G
3
Posts: 77
Reputation: 4,011


Return to How do I....?

Who is online

Users browsing this forum: BipolarMike, Televangelist, totoe and 21 guests