Game Development Reference
In-Depth Information
Next, add the following lines of code to the same class:
private void showMenuButtons (boolean visible) {
float moveDuration = 1.0f;
Interpolation moveEasing = Interpolation.swing;
float delayOptionsButton = 0.25f;
float moveX = 300 * (visible ? -1 : 1);
float moveY = 0 * (visible ? -1 : 1);
final Touchable touchEnabled = visible ? Touchable.enabled
: Touchable.disabled;
btnMenuPlay.addAction(
moveBy(moveX, moveY, moveDuration, moveEasing));
btnMenuOptions.addAction(sequence(
delay(delayOptionsButton),
moveBy(moveX, moveY, moveDuration, moveEasing)));
SequenceAction seq = sequence();
if (visible)
seq.addAction(delay(delayOptionsButton + moveDuration));
seq.addAction(run(new Runnable() {
public void run () {
btnMenuPlay.setTouchable(touchEnabled);
btnMenuOptions.setTouchable(touchEnabled);
}
}));
stage.addAction(seq);
}
private void showOptionsWindow (boolean visible,
boolean animated) {
float alphaTo = visible ? 0.8f : 0.0f;
float duration = animated ? 1.0f : 0.0f;
Touchable touchEnabled = visible ? Touchable.enabled
: Touchable.disabled;
winOptions.addAction(sequence(
touchable(touchEnabled),
alpha(alphaTo, duration)));
}
The two new methods, showMenuButtons() and showOptionsWindow() , will allow
us to easily show or hide the menu buttons and the Options window in an animated
fashion. Any logic involved in the showing and hiding animation is encapsulated in
these methods, which make it much more convenient to use.
 
Search WWH ::




Custom Search