Game Development Reference
In-Depth Information
chkShowFpsCounter.setChecked(prefs.showFpsCounter);
chkUseMonochromeShader.setChecked(prefs.useMonochromeShader);
}
private void saveSettings () {
prefs.showFpsCounter = chkShowFpsCounter.isChecked();
prefs.useMonochromeShader = chkUseMonochromeShader.isChecked();
prefs.save();
}
The last modifications to
GamePreferences
and
MenuScreen
just extended the
settings handling by a new Boolean flag, which can now be toggled via the new
checkbox added to the debug section of the
Options
dialog in the menu screen.
Next, add the following import lines to the
WorldRenderer
class:
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.utils.GdxRuntimeException;
After this, add the following line to the same class:
private ShaderProgram shaderMonochrome;
Also make the following changes to the same class:
private void init () {
batch = new SpriteBatch();
camera = new OrthographicCamera(Constants.VIEWPORT_WIDTH,
Constants.VIEWPORT_HEIGHT);
camera.position.set(0, 0, 0);
camera.update();
cameraGUI = new OrthographicCamera(Constants.VIEWPORT_GUI_WIDTH,
Constants.VIEWPORT_GUI_HEIGHT);
cameraGUI.position.set(0, 0, 0);
cameraGUI.setToOrtho(true); // flip y-axis
cameraGUI.update();
b2debugRenderer = new Box2DDebugRenderer();
shaderMonochrome = new ShaderProgram(
Gdx.files.internal(Constants.shaderMonochromeVertex),
Gdx.files.internal(Constants.shaderMonochromeFragment));
if (!shaderMonochrome.isCompiled()) {
String msg = "Could not compile shader program: "
+ shaderMonochrome.getLog();
throw new GdxRuntimeException(msg);
}
}