Game Development Reference
In-Depth Information
5.6.1 Drag and Drop
One common feature to implement when working with grids is the ability to organize the
items in the grid and to move items from one grid to another. In platforms that support and
input device such as a mouse or touch, drag and drop is the familiar approach. Drag and
drop using a gamepad is not as comfortable though it's certainly possible to do it. When
using gamepads it's often best not to use drag and drop techniques but rather to add mech-
anicstoselectitemsinagrid'sslot,movethecursorandgivetheplayertheabilitytoselect
a target slot into which to “drop” the item.
There are a few behaviors that are expected when developing a drag and drop feature.
Single Click
A single click on an item will set the item in focus, we will mark the item as in-focus and
we will draw an outline to provide feedback to the player.
Click and hold
Clicking and holding will put the item into the drag mode. This means we will temporarily
remove the item from its grid and place it in an intermediate object.
Click and drag
While the mouse button is held, as long as the input device moves, the item's position will
be reflected to that of the input cursor.
Drop into empty grid slot
Dropping an item into an empty grid slot will result in the move of the item. We add the
item into the new grid slot and remove it from the intermediate dragging object.
Drop into same grid slot
This has no effect, we return the item to its source grid slot and remove it from the inter-
mediate dragging object.
Drop into different grid
This operation will result in the item being removed entire from the source grid and added
as a new item of another grid.
Drop into non-empty slot
Search WWH ::




Custom Search