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>

public class ParallaxBackgroundComponent extends RenderComponent
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

    Fields inherited from class com.csse3200.game.components.Component

    enabled, entity, prio
  • Constructor Summary

    Constructors
    Constructor
    Description
    ParallaxBackgroundComponent(com.badlogic.gdx.graphics.Camera camera, float mapWidth, float mapHeight)
    Creates a new parallax background component.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addLayer(com.badlogic.gdx.graphics.Texture texture, float factor)
    Adds a basic parallax layer with default scaling and no offset.
    void
    addLayer(com.badlogic.gdx.graphics.Texture texture, float factor, float offsetX, float offsetY)
    Adds a parallax layer with custom offset but default scaling.
    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.
    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.
    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.
    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.
    void
    draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
    Renders all parallax layers in order from back to front.
    int
    Returns the render layer for this component.

    Methods inherited from class com.csse3200.game.rendering.RenderComponent

    compareTo, create, dispose, getZIndex, render, setLayer

    Methods inherited from class com.csse3200.game.components.Component

    earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 calculations
      mapWidth - The total width of the game map
      mapHeight - 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 layer
      factor - 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 layer
      factor - The parallax factor (0.0 = static, 1.0 = moves with camera)
      offsetX - Horizontal offset in world units
      offsetY - 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 layer
      factor - The parallax factor (0.0 = static, 1.0 = moves with camera)
      offsetX - Horizontal offset in world units
      offsetY - Vertical offset in world units
      scaleX - 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 layer
      factor - The parallax factor (0.0 = static, 1.0 = moves with camera)
      offsetX - Horizontal offset in world units
      offsetY - Vertical offset in world units
      scale - 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 layer
      factor - The parallax factor (0.0 = static, 1.0 = moves with camera)
      tileHorizontally - Whether to tile the texture horizontally
      tileVertically - Whether to tile the texture vertically
      tileWidth - Width of each tile (0 = use texture width)
      tileHeight - Height of each tile (0 = use texture height)
      offsetX - Horizontal offset in world units
      offsetY - 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 layer
      factor - The parallax factor (0.0 = static, 1.0 = moves with camera)
      tileHorizontally - Whether to tile the texture horizontally
      tileVertically - Whether to tile the texture vertically
      tileWidth - 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 units
      offsetY - Vertical offset in world units
      scaleX - Horizontal scale factor for tiles
      scaleY - 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:
      draw in class RenderComponent
      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:
      getLayer in interface Renderable
      Overrides:
      getLayer in class RenderComponent
      Returns:
      The render layer (Integer.MIN_VALUE for background priority)