RPG-Inventory - Drag and Drop

  • 54 favourites



10,513 visits, 24,477 views



This tutorial hasn't been translated.


This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Now, that the item is marked as "dragged", how do we actually move the item?

As long, as drag is true, this event will fire every tick!

Now, we want to drop the item again. There are two possible positions - either on a slot, or somewhere else.

Dropping in the wild is easier, so take a look at this first:

You can see, that we set the item to the last saved position if dropped in the wild. To end the dragging drag has to be set to false!

Now, how about dropping an item into a slot. There are more conditions to be checked:

1. Is the slot eligible to receive the item?

2. Is the slot allready occupied?

Again, easiest first: To check if the slot is occupied, we just have to check its instance variable empty.

The eligibility is checked by calling the function checkAccept

Don't get confused. buffer within this function is a instance variable of the function, even thou it holds the same result as the global buffer varaible.

Now, how do we check, if you may drop the item to this slot?

Take a look, how the function is called:

We pass on two values. One is the slot variable ACCEPTS which hold the binary representation of which flags (0 or 1) are acceptable. The other one is the item variable Acceptable which is the corresponding bit mask.

Within the function we now do the bitwise AND of both bitfields. If the slot does not accept the item, the result will be zero, else it will be anything larger then nill.

The function as is, wil return a string holding the name of an animation. We look this up within the array slotAnim.

You can tell, that we set the animation to the result of the function call and the global buffer to the value of the function buffer.

This controlls the look of the slot.

If the slot is occupied, we set the buffer to zero and the slot animation to deny.


  • Order by
Want to leave a comment? Login or Register an account!