Game Development Reference
In-Depth Information
There's moreā¦
Usually, on a minimap, players will want some kind of indication about their (and others)
whereabouts. Let's implement that in the minimap we just created:
1. First of all, we need to change the
minimap
element in our screen a bit. We set
childLayout
to
absolute
and add another panel inside it called
playerI-
con
with a small width and height.
2. Next, we add a new
Element
field called
playerIcon
to the
GameScreenController
and use
findElementByName
in the
bind
method to set it.
3. Then, we add another method called
updatePlayerPosition
with two in-
tegers,
x
and
y
, as the input.
4. This method should use
setConstraintX
and
setConstraintY
on the
playerIcon
element to set the position. Those methods take
SizeValue
as
the input, and we supply the
x
and
y
values with the
"px"
definition.
5. Finally, in the same method, we need to call
layoutElements()
on the
min-
imap
element to make it update its child elements.
For other things, such as visible enemies, we can use the builder interface to create them as
and when we need them and then use
markForRemoval
to remove them when they're
not needed anymore. An example of this process can be seen in the
Handling a game mes-
sage queue
recipe.