Game Development Reference
In-Depth Information
prefs.sound = chkSound.isChecked();
prefs.volSound = sldSound.getValue();
prefs.music = chkMusic.isChecked();
prefs.volMusic = sldMusic.getValue();
prefs.charSkin = selCharSkin.getSelectedIndex();
prefs.showFpsCounter = chkShowFpsCounter.isChecked();
prefs.save();
}
private void onCharSkinSelected(int index) {
CharacterSkin skin = CharacterSkin.values()[index];
imgCharSkin.setColor(skin.getColor());
}
private void onSaveClicked() {
saveSettings();
onCancelClicked();
}
private void onCancelClicked() {
btnMenuPlay.setVisible(true);
btnMenuOptions.setVisible(true);
winOptions.setVisible(false);
}
The
loadSettings()
and
saveSettings()
methods are used to translate back
and forth between the values stored in the widgets and the instance of the
GamePreferences
class. The methods starting with
on
in their name contain
code that we want to be executed at certain events. The
onCharSkinSelected()
method will update the preview image. The
onSaveClicked()
method saves the
current settings of the
Options
window and swaps the
Options
window for the
menu controls. The
onCancelClicked()
method only swaps the widgets, which
also means that any changed settings will be discarded. The visibility of the menu
controls and the
Options
window is simply toggled by calling
setVisible()
on the
respective widgets.
Next, make the following changes to the same class:
private void rebuildStage() {
skinCanyonBunny = new Skin(
Gdx.files.internal(Constants.SKIN_CANYONBUNNY_UI),
new TextureAtlas(Constants.TEXTURE_ATLAS_UI));
skinLibgdx = new Skin
(Gdx.files.internal(Constants.SKIN_LIBGDX_UI),
new TextureAtlas(Constants.TEXTURE_ATLAS_LIBGDX_UI));