Game Development Reference
In-Depth Information
The showMenuButtons() method has one parameter ( visible ) to control whether
to show or hide the menu buttons. At the beginning of this method, we not only set
many variables that are used to control the overall behavior of the animation, such
as duration and easing, but also set some other variables whose values obviously
depend on the visible flag. After the position, duration, and easing have been
computed, we head over and add a couple of actions to both the menu buttons. The
Play button is going to be directly moved to a relative position while the Options
button does exactly the same but with an added delay prior to its move action. We
will now discuss a pretty exciting example of how flexible actions are. We create a
new and empty sequence and store it in seq . What follows is a conditional delay()
action, so to say, which is only going to be added to the new sequence if the visible
flag is set to true .
This means you can create and script actor behaviors in code while also being able
to dynamically adjust and put them together as needed at a later time as we just
did! Albeit, as a result of the prior condition, we always add a run() action to the
sequence. The run() action takes a Runnable that is used in Java to put the code that
is going to be executed in a separate thread. We use this and the conditional delay()
action to call setTouchable() on the Play and Options buttons, which control
whether the buttons receive and respond to touches and mouse clicks. Finally, the
sequence() action stored in seq is added as a new action to the stage.
In this case, we can safely do this to enqueue the sequence() action
for execution because the sequence does not modify the stage with the
delay() and run() actions.
The showOptionsWindow() method animates the options menu in the same way as
described for the menu buttons in showMenuButtons() . The only difference here is
that it takes a second flag that can be used to skip the animation.
Now, make the following changes to the MenuScreen class:
private Table buildOptionsWindowLayer () {
...
// Make options window slightly transparent
winOptions.setColor(1, 1, 1, 0.8f);
// Hide options window by default
showOptionsWindow(false, false);
if (debugEnabled) winOptions.debug();
// Let TableLayout recalculate widget sizes and positions
winOptions.pack();
// Move options window to bottom right corner
 
Search WWH ::




Custom Search