Inventory Example

This forum is currently in read-only mode.
From the Asset Store
Unlock platyers earning coins, and save it with Localstorage
  • I started putting together an example of how to handle an 'inventory' system. Pretty simple, but a good example of how to use functions I'll improve it later so its got more items and limits etc...at the moment left click picks up, and right click drops

  • Cool! Will be keeping my eyes on this one...

    I started one the other day but it got a little complex.. so I put it to the side for now..

  • Think it'd be possible to make an inventory that you can drag and drop objects out of?

    I was trying to think up how to do it but couldn't.

  • I made a start on one that was going to allow that. Also, something like a sword could take up 6 squares and if you replaced it with something that took up 4, it'd be an automatic switch over. At least that's what I had in mind but it's not as easy as it sounds. Might have another go at the weekend.

  • Adjusting the index value shuffles them around so its possible. Its just a case of making the events organised enough that it doesn't get confusing or messy.

    If you have 8 spots and you have a sword that takes up 4, and 4 different potions which take up 1...then how would you move the sword about? Would you just drag and drop it over the potions, and everything else would automatically shuffle to give the sword room ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Adjusting the index value shuffles them around so its possible. Its just a case of making the events organised enough that it doesn't get confusing or messy.

    If you have 8 spots and you have a sword that takes up 4, and 4 different potions which take up 1...then how would you move the sword about? Would you just drag and drop it over the potions, and everything else would automatically shuffle to give the sword room ?

    It would be exactly like in Diablo II... if you don't have slots available, you have to drop the item and reshuffle your inventory spaces to make room. A lot of people found that "annoying" but I find it in true RPG spirit... reordering your bag-o-goodies to shovel in one last treasure! You can always swap a smaller or same sized item for something bigger (or same sized >.>) but putting a larger item in place of a smaller one would require the spaces to be there already.

    You could always make an "auto sort" function (like in Sacred 2) which arranges your inventory for "best fit".

    ~Sol

  • Yeah swapping the other way round would be a nightmare since you'd have to work out what to do with the multiple items you've replaced by the sword. I'll finish off my crappy shooter thing today and then set about this and see if I have better luck this time around. Would be good to see David finish at the same time and people could see 2 different methods of doing it. Mine will be the messier one by far

  • Hashtable Object would be the best to use for inventory system, at least that is what I believe. Alternatively you could just create 'inventory slot' sprites that would store anything thrown at them, but hashtable is more flexible - you can create a dynamic number of inventory slots for each existing key.

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