MinigameRenderer - UQcsse3200/2024-studio-2 GitHub Wiki
The MinigameRenderer class is responsible for rendering mini-games in a LibGDX application. It manages a collection of MinigameRenderable objects and uses an OrthographicCamera to control the rendering viewport.
Class Overview
public MinigameRenderer() {
// Constructor
}
public void addRenderable(MinigameRenderable renderable) {
// Add renderable objects to the list
}
public void render() {
// Render all added renderable objects
}
public void resize(int width, int height) {
// Adjust the camera viewport on screen resize
}
public SpriteBatch getSb() {
return this.sb;
}
public OrthographicCamera getCam() {
return this.cam;
}
public void dispose() {
// Dispose of the SpriteBatch resources
}
Fields
DEFAULT_WIDTH
: The default width of the camera viewport.DEFAULT_HEIGHT
: The default height of the camera viewport.sb
: The SpriteBatch used for drawing 2D sprites.cam
: The OrthographicCamera that defines the viewport for rendering.renderables
: A list of objects that implement the MinigameRenderable interface, which defines objects to be rendered.
Constructor
MinigameRenderer()
Initialises the MinigameRenderer
with a new SpriteBatch
and sets up the OrthographicCamera
with default dimensions. The camera is centred on the viewport and updated.
Methods
void addRenderable(MinigameRenderable renderable)
Adds a MinigameRenderable
object to the list of renderables. These objects are expected to implement a render()
method that will be called during the render process.
Parameters:
renderable
: An instance of MinigameRenderable to be added to the list.
void render()
Begins the SpriteBatch
and renders all objects in the renderables list by calling their render()
method. This method is intended to be called during the game's render loop.
void resize(int width, int height)
Adjusts the camera's viewport based on the new screen dimensions. This method should be called whenever the game window is resized to ensure the aspect ratio and viewport are correctly maintained.
Parameters:
width
: The new width of the game window.
height
: The new height of the game window.
SpriteBatch getSb()
Returns the SpriteBatch
used by the renderer.
Returns:
SpriteBatch
: The SpriteBatch instance.
OrthographicCamera getCam()
Returns the OrthographicCamera
used by the renderer.
Returns:
OrthographicCamera
: The OrthographicCamera instance.
void dispose()
Disposes of the SpriteBatch
resources. This method should be called when the MinigameRenderer is no longer needed to free up resources.
Usage example
MinigameRenderer renderer = new MinigameRenderer();
MinigameRenderable object = new SomeRenderable();
renderer.addRenderable(object);
renderer.render(); // Call during the render loop
renderer.resize(1024, 768); // Call during window resize
renderer.dispose(); // Call when cleaning up resources