Class ParallaxBackgroundComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.rendering.RenderComponent
com.csse3200.game.rendering.parallax.ParallaxBackgroundComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable,Renderable,Comparable<Renderable>
A render component that creates parallax scrolling backgrounds with multiple layers.
This component manages a collection of parallax layers that scroll at different speeds
relative to the camera movement, creating a depth effect.
The component supports both tiled and stretched background layers, with configurable
scaling, offsets, and parallax factors for each layer.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionParallaxBackgroundComponent(com.badlogic.gdx.graphics.Camera camera, float mapWidth, float mapHeight) Creates a new parallax background component. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLayer(com.badlogic.gdx.graphics.Texture texture, float factor) Adds a basic parallax layer with default scaling and no offset.voidaddLayer(com.badlogic.gdx.graphics.Texture texture, float factor, float offsetX, float offsetY) Adds a parallax layer with custom offset but default scaling.voidaddLayer(com.badlogic.gdx.graphics.Texture texture, float factor, float offsetX, float offsetY, float scaleX, float scaleY) Adds a parallax layer with custom offset and scaling.voidaddScaledLayer(com.badlogic.gdx.graphics.Texture texture, float factor, float offsetX, float offsetY, float scale) Adds a parallax layer with uniform scaling and custom offset.voidaddTiledLayer(com.badlogic.gdx.graphics.Texture texture, float factor, boolean tileHorizontally, boolean tileVertically, float tileWidth, float tileHeight, float offsetX, float offsetY) Adds a tiled parallax layer with custom offset.voidaddTiledLayer(com.badlogic.gdx.graphics.Texture texture, float factor, boolean tileHorizontally, boolean tileVertically, float tileWidth, float tileHeight, float offsetX, float offsetY, float scaleX, float scaleY) Adds a tiled parallax layer with custom offset and scaling.voiddraw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Renders all parallax layers in order from back to front.intgetLayer()Returns the render layer for this component.Methods inherited from class com.csse3200.game.rendering.RenderComponent
compareTo, create, dispose, getZIndex, render, setLayerMethods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
ParallaxBackgroundComponent
public ParallaxBackgroundComponent(com.badlogic.gdx.graphics.Camera camera, float mapWidth, float mapHeight) Creates a new parallax background component.- Parameters:
camera- The camera to track for parallax calculationsmapWidth- The total width of the game mapmapHeight- The total height of the game map
-
-
Method Details
-
addLayer
public void addLayer(com.badlogic.gdx.graphics.Texture texture, float factor) Adds a basic parallax layer with default scaling and no offset. The layer will be stretched to fit the viewport.- Parameters:
texture- The texture to use for this layerfactor- The parallax factor (0.0 = static, 1.0 = moves with camera)
-
addLayer
public void addLayer(com.badlogic.gdx.graphics.Texture texture, float factor, float offsetX, float offsetY) Adds a parallax layer with custom offset but default scaling. The layer will be stretched to fit the viewport.- Parameters:
texture- The texture to use for this layerfactor- The parallax factor (0.0 = static, 1.0 = moves with camera)offsetX- Horizontal offset in world unitsoffsetY- Vertical offset in world units
-
addLayer
public void addLayer(com.badlogic.gdx.graphics.Texture texture, float factor, float offsetX, float offsetY, float scaleX, float scaleY) Adds a parallax layer with custom offset and scaling. The layer will be stretched to fit the viewport with the specified scale.- Parameters:
texture- The texture to use for this layerfactor- The parallax factor (0.0 = static, 1.0 = moves with camera)offsetX- Horizontal offset in world unitsoffsetY- Vertical offset in world unitsscaleX- Horizontal scale factor (1.0 = original size)scaleY- Vertical scale factor (1.0 = original size)
-
addScaledLayer
public void addScaledLayer(com.badlogic.gdx.graphics.Texture texture, float factor, float offsetX, float offsetY, float scale) Adds a parallax layer with uniform scaling and custom offset. Convenience method for when you want the same scale factor for both X and Y axes.- Parameters:
texture- The texture to use for this layerfactor- The parallax factor (0.0 = static, 1.0 = moves with camera)offsetX- Horizontal offset in world unitsoffsetY- Vertical offset in world unitsscale- Uniform scale factor applied to both X and Y axes
-
addTiledLayer
public void addTiledLayer(com.badlogic.gdx.graphics.Texture texture, float factor, boolean tileHorizontally, boolean tileVertically, float tileWidth, float tileHeight, float offsetX, float offsetY) Adds a tiled parallax layer with custom offset. The texture will be repeated across the specified dimensions instead of being stretched.- Parameters:
texture- The texture to use for this layerfactor- The parallax factor (0.0 = static, 1.0 = moves with camera)tileHorizontally- Whether to tile the texture horizontallytileVertically- Whether to tile the texture verticallytileWidth- Width of each tile (0 = use texture width)tileHeight- Height of each tile (0 = use texture height)offsetX- Horizontal offset in world unitsoffsetY- Vertical offset in world units
-
addTiledLayer
public void addTiledLayer(com.badlogic.gdx.graphics.Texture texture, float factor, boolean tileHorizontally, boolean tileVertically, float tileWidth, float tileHeight, float offsetX, float offsetY, float scaleX, float scaleY) Adds a tiled parallax layer with custom offset and scaling. The texture will be repeated with the specified scale applied to each tile.- Parameters:
texture- The texture to use for this layerfactor- The parallax factor (0.0 = static, 1.0 = moves with camera)tileHorizontally- Whether to tile the texture horizontallytileVertically- Whether to tile the texture verticallytileWidth- Width of each tile before scaling (0 = use texture width)tileHeight- Height of each tile before scaling (0 = use texture height)offsetX- Horizontal offset in world unitsoffsetY- Vertical offset in world unitsscaleX- Horizontal scale factor for tilesscaleY- Vertical scale factor for tiles
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Renders all parallax layers in order from back to front. Called automatically by the rendering system.- Specified by:
drawin classRenderComponent- Parameters:
batch- The sprite batch to use for rendering
-
getLayer
public int getLayer()Returns the render layer for this component. Parallax backgrounds are rendered at the lowest priority to appear behind other elements.- Specified by:
getLayerin interfaceRenderable- Overrides:
getLayerin classRenderComponent- Returns:
- The render layer (Integer.MIN_VALUE for background priority)
-