Overview
TheScoreScreen class displays the player’s final score at the end of a game session. It provides a simple UI overlay with the score and a button to return to the main menu.
Package: com.pmm.games.screens
Implements: Screen (libGDX)
Purpose
This screen serves as the game-over screen, showing players their final score and providing navigation back to the main menu. It uses Scene2D for UI management and creates a semi-transparent overlay to display the score information.Constructor
ScoreScreen
score(int) - The final score to display to the player
Properties
| Property | Type | Description |
|---|---|---|
stage | Stage | Scene2D stage managing the UI elements |
score | int | The player’s final score |
showScoreScreen | boolean | Flag indicating whether screen should remain visible |
table | Table | Main layout table for UI arrangement |
Methods
show
- Creates a semi-transparent background (300x150 pixels, yellow tint with 30% opacity)
- Displays the score with label “Tu puntuación: ” at 2x font scale
- Adds a “MENÚ” button to return to the main menu
- Loads UI skin from
skins/uiskin.json
render
delta(float) - Time elapsed since last frame in seconds
resize
width(int) - New window widthheight(int) - New window height
isShowScoreScreen
true if screen should continue showing, false if it should close (user clicked menu button)
Example:
pause / resume / hide
dispose
UI Components
The ScoreScreen creates the following UI elements:- Background: Semi-transparent yellow rectangle (300x150px, 30% opacity)
- Score Label: Displays “Tu puntuación: ” with 2x font scaling
- Menu Button: “MENÚ” button (100x30px) that sets
showScoreScreento false when clicked
Integration with Game
The ScoreScreen is typically shown when the game ends. The calling code should:- Create the ScoreScreen with the final score
- Set it as the active screen
- Monitor
isShowScoreScreen()to detect when user wants to return to menu - Dispose the screen when transitioning away
Dependencies
- libGDX Core: For Screen interface and graphics
- Scene2D: For UI management (Stage, Table, Label, TextButton)
- UI Skin: Requires
skins/uiskin.jsonfile in assets
Notes
- The screen displays text in Spanish (“Tu puntuación”, “MENÚ”)
- Uses a semi-transparent overlay that doesn’t obscure the underlying game screen
- Input handling is automatically set to the stage in the constructor
- The background is created programmatically using Pixmap for flexibility