Game Development Reference
In-Depth Information
How it works...
The Java Builder interface we use to create item slots takes a while to get used to, but it's a
really powerful tool when we have the need to create nifty elements dynamically. In this
case, we still use a predefined control. This saves us a couple of lines of code and allows
someone else than a coder to edit the layout and style of the component since it's exposed
in the XML file.
By default, a
Droppable
control will always accept the
Draggable
control that is be-
ing dropped. The
accept
method in
DroppableDropFilter
enables us to define
what should be accepted or not. It's illustrated in this recipe by only accepting
Invent-
oryItems
of a certain type. The method parameters for the accept method can be de-
scribed, as the first
Droppable
is the control that the
draggable
control is being
picked up from. The
Draggable
control is the item that is being moved. The second
Droppable
control is the target where
Draggable
has been dropped.
Tip
At the time of writing this, the first
Droppable
control tends to be null the first time a
Draggable
control is being moved.