CutSceneScreen - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

The CutSceneScreen class is part of the game's screen management system and represents a narrative cutscene that the player experiences before transitioning to the next game state. It handles the display of a cutscene with background visuals, a story text that reveals character-by-character, and background audio, along with a "Continue" button that allows the player to proceed to the next screen.


Functionality

  • Character-by-Character Text Reveal: Displays a block of text that is gradually revealed, simulating a typewriter effect telling the user about the story
  • Background Visual and Audio: Plays a custom background image and sound during the cutscene.
  • User Interaction: Provides a "Continue" button for users to advance to the next game screen.
  • Stage and Asset Management: Utilizes LibGDX's Stage and Skin for UI, and handles asset loading for textures, fonts, and sounds.

Key Methods

Constructor: CutSceneScreen(GdxGame game)

  • Initialises the cutscene screen, loading assets (e.g., images, sounds), setting up UI components (e.g., labels, buttons), and assigning the input processor.
public CutSceneScreen(GdxGame game) {
    this.game = game;
    // Initialization logic including asset loading, creating cutscene and button
}

loadAssets()

  • Loads the required assets for the cutscene, including the background image and sound.
private void loadAssets() {
    cutSceneTexture = new Texture(Gdx.files.internal("images/animal/Black and White Modern Forest Scenery At Night Desktop Wallpapaer.png"));
    cutSceneSound = Gdx.audio.newSound(Gdx.files.internal("sounds/animal/birds-and-animals-before-sunrise-246785.mp3"));
}

createCutScene()

  • Sets up the text and layout of the cutscene. The full text of the story is revealed character-by-character as the cutscene progresses.
private void createCutScene() {
    fullText = "Once upon a time, after humans mysteriously vanished...";
    displayedText = new StringBuilder(); // Initialize displayed text
    label = new Label("", labelStyle);  // Empty label initially
    stage.addActor(table); // Add label to stage
}

createContinueButton()

  • Creates the "Continue" button that allows the player to proceed to the next screen, such as the animal selection screen. The button is added to the stage and listens for clicks.
private void createContinueButton() {
    CustomButton continueButton = new CustomButton("Continue", skin);
    continueButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.setScreen(GdxGame.ScreenType.ANIMAL_SELECTION);
        }
    });
    stage.addActor(continueButton); // Add button to stage
}

render(float delta)

  • Manages the rendering of the cutscene screen. This includes updating the entity service, drawing the background image, and gradually revealing the text.
@Override
public void render(float delta) {
    spriteBatch.begin();
    spriteBatch.draw(cutSceneTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    spriteBatch.end();
    // Text reveal logic
    if (currentCharacterIndex < fullText.length()) {
        displayedText.append(fullText.charAt(currentCharacterIndex));
        label.setText(displayedText.toString());
        currentCharacterIndex++;
    }
    stage.act(delta);
    stage.draw();
}

dispose()

  • Releases resources (e.g., textures, sounds, sprite batches) when the cutscene screen is no longer needed.
@Override
public void dispose() {
    spriteBatch.dispose();
    stage.dispose();
    cutSceneTexture.dispose();
    if (cutSceneSound != null) {
        cutSceneSound.dispose();
    }
}

Key Properties

  • game: Reference to the main game object to facilitate transitioning to other screens.
  • cutSceneSound: The sound effect that plays during the cutscene.
  • cutSceneTexture: The background image of the cutscene.
  • label: Displays the cutscene text which is revealed character-by-character.
  • stage: Manages UI elements like the text label and buttons.

Usage

To display the cutscene, instantiate the CutSceneScreen and set it as the active screen in your game:

CutSceneScreen cutSceneScreen = new CutSceneScreen(game);
game.setScreen(cutSceneScreen);

Once the cutscene finishes or the "Continue" button is pressed, the game transitions to the next state.###

Additional Notes

  • The cutscene sound will automatically play once the screen is loaded and will stop when the screen is disposed.

Image

Video

Video Link for Testing purpose ( it does not include background music ) : https://youtu.be/THPp7MdA00Q

UML

image