Scene - UQcsse3200/2024-studio-3 GitHub Wiki
The Scene
class represents an individual segment or phase within a cutscene in the game. It encapsulates all the visual and textual elements for that specific moment in the cutscene, including background images, animations, static images, text dialogue, and the duration the scene will be displayed. Each cutscene is composed of multiple scenes, and the Scene
class plays a vital role in defining the content and structure of each one.
The Scene
class is responsible for:
- Defining Visual Content: This includes the background image, any animations, and additional images that will be displayed during the scene.
- Text Management: It holds the dialogue or text that will be shown on screen during the scene.
- Timing: It controls how long the scene will last before transitioning to the next one.
- Scene Layout: Positions of animations and images are managed by the class, allowing for proper placement of visual elements within the scene.
-
Background Image:
-
backgroundImagePath
: The file path to the background image displayed during the scene. It provides the main visual backdrop.
-
-
Animations:
-
animationImagePaths
: An array of file paths for the images used in any animations for the scene. -
animationPositions
: An array ofVector2
objects that define the positions of the animation elements within the scene. These properties are useful when you want to display moving or changing visual elements (e.g., characters performing actions) on top of the background.
-
-
Static Images:
-
imagePaths
: An array of file paths for static images displayed during the scene. -
imagePositions
: An array ofVector2
objects that define where these images will appear in the scene. -
imageScales
: An array that determines the scaling factor for each static image, allowing them to appear larger or smaller. These properties handle non-animated elements (e.g., UI elements or characters in fixed poses).
-
-
Text Dialogue:
-
sceneText
: An array that holds the dialogue or text shown during the scene. This is typically used to convey narrative information to the player.
-
-
Duration:
-
duration
: The time (in seconds) the scene will be displayed before moving on to the next one in the cutscene sequence.
-
The Scene
class is used within a cutscene to define each segment's visuals and narrative elements. Each cutscene can have multiple scenes, which are managed by the Cutscene
class. A scene typically consists of a background, one or more images or animations, and the text to be displayed during that scene. The duration
of each scene controls how long it is visible before the cutscene transitions to the next one.
-
Initialization: When a
Scene
is created, it requires a background image. Additional components like animations, static images, or text can be added later through setter methods.Scene scene = new Scene("images/Cutscenes/Scene1_Background.png");
-
Setting Images and Animations: Static images and animations can be added with their corresponding positions and scales. This allows flexible placement of characters or other elements on the screen.
scene.setImages( new String[]{"images/player.png", "images/npc.png"}, new Vector2[]{new Vector2(0, 0), new Vector2(5, 5)}, new float[]{1.0f, 2.0f} ); scene.setAnimationImages( new String[]{"images/anim1.atlas", "images/anim2.atlas"}, new Vector2[]{new Vector2(2, 3), new Vector2(7, 8)} );
-
Setting Dialogue Text: The dialogue or text for the scene can be added using the
setSceneText()
method. The text is stored in an array, and each string represents a line or section of text that can be displayed during the scene.Array<String> dialogue = new Array<>(); dialogue.add("Character: Welcome to the game!"); dialogue.add("Character: Let's get started."); scene.setSceneText(dialogue);
-
Duration: The scene’s
duration
dictates how long it will be displayed before moving to the next scene. This duration is usually set based on how long the text or animations take to be fully understood or completed.scene.setDuration(5.0f); // Scene will last 5 seconds
-
Usage in Cutscenes: Once a scene is set up, it is added to a list of scenes in the
Cutscene
class. TheCutscene
will then manage transitioning between these scenes, displaying the visuals and text, and ensuring smooth transitions based on the scene's duration.
The class also includes basic error handling for mismatched arrays. For example, when setting animation or image properties, it ensures that the number of image paths matches the number of positions or scales provided. If these sizes do not match, an error is logged.
if (imagePaths.length != imagePositions.length) {
logger.error("Image paths size does not match the position size");
}
The Scene
class is a modular building block that defines individual scenes within a cutscene. It provides methods to manage visual elements, text, and scene timing, and ensures smooth transitions between scenes. The class is designed to be flexible, allowing for various configurations of background images, animations, and static images, while also managing dialogue text and scene durations.