-
Notifications
You must be signed in to change notification settings - Fork 4
Loadingscreen
The LoadingScreen
class is responsible for displaying a loading animation and transitioning to the main game screen from the TurretSelectSCreen once all the required assets are loaded.
The LoadingScreen
class serves as an intermediary screen between TurretSelect and transitioning to the main game. During this phase, it loads essential assets and displays a loading animation, ensuring that the player does not enter the game prematurely.
-
LoadingScreen(GdxGame game)
-
Description: The class constructor for
LoadingScreen
. -
Parameters:
game
- The game instance to which this screen belongs. -
Initialization:
- Initializes the
SpriteBatch
. - Loads the background image and creates a
Texture
object. - Initializes the stage for UI elements.
- Initializes a
Label
element to display "Loading." - Sets the UI skin using the
uiskin.json
file.
- Initializes the
-
Description: The class constructor for
-
render(float delta)
- Description: Called in the game loop to render the loading screen and handle the transition to the main game.
-
Parameters:
delta
- The time in seconds since the last frame. -
Processing Steps:
- Renders the background image and loading animation.
- Checks if all assets are loaded or if a set time has elapsed (1.5 seconds).
- If the loading is complete, triggers the transition to the main game.
- Updates the loading label with dots to indicate the loading progress.
-
resize(int width, int height)
- Description: Called when the screen should resize itself, maintaining the aspect ratio.
-
Parameters:
width
- The new width of the screen,height
- The new height of the screen.
-
pause()
- Description: Called when the application is paused. No specific handling is implemented in this class.
-
resume()
- Description: Called when the application is resumed from a paused state. No specific handling is implemented in this class.
-
hide()
- Description: Called when this screen is no longer the current screen for the game. No specific handling is implemented in this class.
-
dispose()
- Description: Called when disposing of the screen to free up resources.
-
Resource Cleanup:
- Disposes of the
SpriteBatch
, background texture, and any other resources created in the constructor.
- Disposes of the
-
LoadingScreen
is set usinggame.setScreen(GdxGame.ScreenType.LOAD_SCREEN)
in the turret select. - It transitions to the main game screen using the
game.setScreen(GdxGame.ScreenType.MAIN_GAME)
method when the loading is complete. - The loading progress is tracked using
AssetLoader.areAllAssetsLoaded()
to ensure that all game assets are loaded before entering the main game. The assets being loaded are managed by other classes within the game.
Here is a code snippet representing the key aspects of the LoadingScreen
class:
public class LoadingScreen implements Screen {
if (AssetLoader.areAllAssetsLoaded() || elapsedTime >= 1.5) {
transitionToMainGame = true;
}
if (transitionToMainGame) {
// Transition to the main game screen
game.setScreen(GdxGame.ScreenType.MAIN_GAME);
}
dotTimer += delta;
int numDots = (int) (dotTimer % 1 * 3); // Add a dot every second
// Add dots to the label text
StringBuilder labelText = new StringBuilder("Loading");
for (int i = 0; i < numDots; i++) {
labelText.append('.');
}
loadingLabel.setText(labelText);
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.