Game Development Reference
In-Depth Information
How it works...
Once the
addMessage
method is called in the
Controller
class,
ControlBuilder
creates a new
gameMessage
instance. The
interactOnClick
element tells
gameMessage
to call
removeMessage
when clicked, supplying its index as
id
.
After its built and added to
messageQueue
, we populate the title and content elements of
the message. Using
#
in the ID of these elements is preferred by Nifty for non-unique IDs.
The
gameMessage
instance is not visible upon creation, and we call
show()
to make it
play the
onShow
effect we defined.
The
Move
effect is set up to have
offsetX
, which is outside of the screen. If it's too low,
there will be a pop effect as it comes into existence. It's set to reach the target position in
100 ms. Messages will stack up nicely without any additional work when they are added.
The messages are set to disappear when clicked, as defined in the builder, through the
in-
teractOnClick
method. Instead of just removing them, we want to play a short fade ef-
fect to make the transition smoother. Simply hiding them won't be enough in this case
either. Since they still occupy a position in the
messageQueue
panel, the remaining mes-
sages won't align properly.
Hence, we want to call
markForRemoval
on the
gameMessage
element. Doing this
instantly, however, would remove it before our hide effect is played. This why we supply
an
EndNotify
object that is handled once the hide effect is done with playing; then, we
add the
markForRemoval
call in here instead.