Game Development Reference
In-Depth Information
winOptions.add(buildOptWinSkinSelection()).row();
// + Debug: Show FPS Counter
winOptions.add(buildOptWinDebug()).row();
// + Separator and Buttons (Save, Cancel)
winOptions.add(buildOptWinButtons()).pad(10, 0, 10, 0);
// Make options window slightly transparent
winOptions.setColor(1, 1, 1, 0.8f);
// Hide options window by default
winOptions.setVisible(false);
if (debugEnabled) winOptions.debug();
// Let TableLayout recalculate widget sizes and positions
winOptions.pack();
// Move options window to bottom right corner
winOptions.setPosition
(Constants.VIEWPORT_GUI_WIDTH - winOptions.getWidth() - 50,
50);
return winOptions;
}
This method contains the code that initializes the
Options
window. It builds each
part of the menu using the
build
methods that we just implemented before this one.
The
Options
window is set to an opacity value of 80 percent. This makes the window
appear slightly transparent, which adds a nice visual detail to it. The call of the
pack()
method of the
Window
widget makes sure that
TableLayout
recalculates the
widget sizes and positions them so that all added widgets will correctly fit into the
window. After this, the window is moved to the bottom-right corner of the screen.
Last but not least, make the following changes to the
onOptionsClicked()
method:
private void onOptionsClicked() {
loadSettings();
btnMenuPlay.setVisible(false);
btnMenuOptions.setVisible(false);
winOptions.setVisible(true);
}
Finally, the added code allows the
Options
window to be opened. The settings are
loaded before the
Options
window is shown so that the widgets will always be
correctly initialized.