-
Notifications
You must be signed in to change notification settings - Fork 4
SettingsScreen
The SettingsScreen
class is responsible for rendering the settings screen in the game. It provides players with options to configure the game settings. This wiki page provides insights into the background image settings_bg
and key methods within the class.
The settings screen uses a background image named "settings_bg" to create an appealing visual environment. This background image enhances the aesthetics of the settings screen, providing an engaging user interface.
This constructor initializes the SettingsScreen
class and loads necessary assets.
/**
* Creates a new instance of the SettingsScreen.
*
* @param game The game instance.
*/
public SettingsScreen(GdxGame game) {
this.game = game;
this.batch = new SpriteBatch();
backgroundTexture = new Texture("images/background/settings/settings_bg.png");
// Initialize services
ServiceLocator.registerInputService(new InputService());
ServiceLocator.registerResourceService(new ResourceService());
ServiceLocator.registerEntityService(new EntityService());
ServiceLocator.registerRenderService(new RenderService());
ServiceLocator.registerTimeSource(new GameTime());
// Create a renderer
renderer = RenderFactory.createRenderer();
// Set the camera position
renderer.getCamera().getEntity().setPosition(5f, 5f);
loadAssets();
createUI();
}
This method is responsible for rendering the settings screen, including the background image.
/**
* Renders the main gameplay screen.
*
* @param delta The time elapsed since the last frame in seconds.
*/
@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
ServiceLocator.getEntityService().update();
// Render the background
float screenWidth = Gdx.graphics.getWidth();
float screenHeight = Gdx.graphics.getHeight();
batch.begin();
batch.draw(backgroundTexture, 0, 0, screenWidth, screenHeight);
batch.end();
renderer.render();
}
This method handles window resizing and updates the stage's viewport.
/**
* Called when the game window is resized.
*
* @param width The new width of the window.
* @param height The new height of the window.
*/
@Override
public void resize(int width, int height) {
renderer.resize(width, height);
// Update the stage's viewport
ServiceLocator.getRenderService().getStage().getViewport().update(width, height, true);
logger.trace("Resized renderer: ({} x {})", width, height);
renderer.resize(width, height);
}
The dispose
method performs cleanup tasks when the settings screen is no longer needed, such as disposing of resources and services.
/**
* Disposes of resources and services associated with the settings screen.
*/
@Override
public void dispose() {
logger.debug("Disposing settings screen");
renderer.dispose();
unloadAssets();
ServiceLocator.getRenderService().dispose();
ServiceLocator.getEntityService().dispose();
batch.dispose();
ServiceLocator.clear();
}
This method loads assets required for the settings screen, including the background texture.
/**
* Loads the assets required for the settings screen.
*/
private void loadAssets() {
logger.debug("Loading assets");
ResourceService resourceService = ServiceLocator.getResourceService();
resourceService.loadTextures(SettingsTextures);
backgroundTexture = new Texture("images/background/settings/settings_bg.png");
ServiceLocator.getResourceService().loadAll();
}
The unloadAssets
method unloads assets that were previously loaded for the settings screen.
/**
* Unloads the assets that were previously loaded for the settings screen.
*/
private void unloadAssets() {
logger.debug("Unloading assets");
ResourceService resourceService = ServiceLocator.getResourceService();
resourceService.unloadAssets(SettingsTextures);
}
This method creates the settings screen's user interface components for rendering and handling user input.
/**
* Creates the setting screen's UI, including components for rendering UI elements to the screen
* and capturing and handling UI input.
*/
private void createUI() {
logger.debug("Creating UI");
Stage stage = ServiceLocator.getRenderService().getStage();
Entity ui = new Entity();
ui.addComponent(new SettingsMenuDisplay(game)).addComponent(new InputDecorator(stage, 10));
ServiceLocator.getEntityService().register(ui);
}
In the testing phase, we initially attempted to simulate various scenarios through general mocking by creating a test file. However, it became evident that this approach was not feasible. Consequently, we shifted to a more visual approach. This testing method involved a series of actions, such as adjusting the screen resolution from the settings menu, and repeatedly minimizing and maximizing the screen. The primary goal was to verify the consistency of the sprites with both the background image and the background image in relation to changes in screen size.