How do I use drag and drop in an inventory successfully?

0 favourites
  • 4 posts
From the Asset Store
320 high-quality cinematic sound effects for trailers and game scenes.
  • Hi,

    I am developing an inventory system for my survival game but I came across some problems with snapping each item into its inventory slot. The system uses sprites to represent the items in your inventory. The sprites have the drag and drop behavior so you can move them around. The slots in the inventory allow for the items to be organized. When items are overlapping the inventory slots, the game does a bunch of checks to make sure that slot is not already taken. If it isn't then the item will easily snap to the slot. This works great. The trouble comes when another item is dropped over the occupied slot. The slots have a boolean that is true when it is occupied. The item dropped on the occupied item will then freeze in its position and not find a new slot to snap too. The item will in fact find a new open slot when it is dropped outside the inventory, not overlapping a slot. Here are the events, the inventory itself, and the problem with overlapping:

    I am really stumped on how to make this work, this is the final piece to creating a working inventory. Everything else is working flawlessly to this point except for this, can anyone help?

    Tagged:

  • Are you trying to set it to the lowest slot available like when you drop it outside the inventory or are you saying you want it to snap back to the slot it was just in?

    To pick the lowest slot available think about it, you need to apply the logic 'pick slot with lowest number that is not occupied' in this scenario, same as when you drop it outside the inventory. Instead under the isOccupied check you replace 'slotnumber = invslot.number' with the 'pick slot with lowest number and is not occupied' condition.

    If the expected behaviour is the latter that it snaps back to the slot it was just dragged from the problem is to do with inventory slots being picked. In the events you have narrowed it down to pick the invslot you are overlapping and only this, so you cannot then pick the previous invslot it was assigned. To fix this you open up the instances again to be picked by adding a 'Pick all invslots' condition above the condition you have now. This will then allow it to pick the previous invslot based on item variable.

  • Thanks for the help! sorry about the longer wait for a response, i was busy this week. The pick all condition worked great! My inventory system is now fixed

  • 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! sorry about the longer wait for a response, i was busy this week. The pick all condition worked great! My inventory system is now fixed

    Great :)

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