Enemy Transition CutScene Screen - UQcsse3200/2024-studio-2 GitHub Wiki
Class Overview
EnemyTransitionCutSceneScreen
is responsible for displaying the transition cutscene between the player and an enemy. The class extends the ScreenAdapter
and manages rendering the background, player, and enemy textures, along with any UI elements. It acts as the entry point for triggering the cutscene when the player encounters an enemy and defeats it
Class Hierarchy
- com.badlogic.gdx.ScreenAdapter
- com.csse3200.game.screens.EnemyTransitionCutSceneScreen
Constructor
EnemyTransitionCutSceneScreen(GdxGame game, Entity enemy)
-
Parameters:
game
: The main game object (GdxGame
) that controls the game flow.enemy
: AnEntity
object representing the enemy the player encounters in the cutscene.
-
Description: This constructor initializes the stage and background texture, sets the player's and enemy's textures, and prepares the skin for UI elements.
Public Methods
void displayTextures()
- Description: Displays both the player's and the enemy's textures on the stage. The player and enemy images are positioned and sized according to the screen dimensions and added as actors to the stage.
void getEnemy(Entity enemy)
-
Parameters:
enemy
: AnEntity
representing the enemy.
-
Description: Assigns the appropriate enemy texture based on the type of enemy encountered, using a switch statement. If no matching type is found, a blank texture is set.
void resize(int width, int height)
-
Parameters:
width
: The new width of the screen.height
: The new height of the screen.
-
Description: Updates the viewport of the stage to adapt to the new screen size.
void dispose()
- Description: Releases the resources used by the stage, background texture, sprite batch, and skin when the screen is no longer needed.
void render(float delta)
-
Parameters:
delta
: The time in seconds since the last render.
-
Description: Clears the screen and renders the background texture and the actors on the stage. The
act
anddraw
methods of the stage are called to update and render the UI elements and images.
void show()
- Description: Called when this screen becomes the current screen of the game. This method can be used for setup actions or initialization when the screen is displayed.
Private Methods
void initializeSkin()
- Description:
Loads the
flat-earth
UI skin from the internal file system. The skin is used to style the UI elements like labels and buttons.
void initializeBackground()
- Description: Loads the texture for the cutscene background from the internal file system. This background image is displayed behind the player and enemy textures.
Textures and Resources
-
Background Texture:
- Path:
images/EnemyTransition.png
- Purpose: The backdrop for the enemy transition cutscene.
- Path:
-
Player Texture:
- Loaded based on
GameState.player.selectedAnimalPath
. - Represents the animal selected by the player.
- Loaded based on
-
Enemy Textures:
- Loaded based on the type of enemy from the
Entity
parameter. - Examples:
chicken_idle.png
,frog_idle.png
,kangaroo_idle.png
, etc.
- Loaded based on the type of enemy from the
-
UI Skin:
flat-earth/skin/flat-earth-ui.json
: A JSON file that defines the UI theme.
Screen Lifecycle
- show(): Triggered when the screen is first displayed.
- render(float delta): Called every frame to draw the screen contents.
- resize(int width, int height): Adjusts the viewport when the screen size changes.
- dispose(): Cleans up resources when the screen is no longer used.
Additional Notes
- The screen relies on
ServiceLocator
to get the stage. - The
SpriteBatch
is used to render the background, whileStage
manages the actors (i.e., the player and enemy images). - The use of the
TextureRegionDrawable
allows for easy display of textures inImage
widgets.
##Image