0 favourites
  • 5 posts
From the Asset Store
Template for maintaining an inventory with crafting possibilities. Completely documented in text and video.
  • 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?



  • 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)

  • 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)

  • 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.)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the help guys, I went with cincipons idea which was similar to my own. Now my inventory works fine :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)