Class ParallaxLayer

java.lang.Object
com.csse3200.game.rendering.parallax.ParallaxLayer

public class ParallaxLayer extends Object
Represents a single layer in a parallax background system. Each layer can scroll at a different speed relative to the camera movement, creating depth perception. Layers can be either tiled (repeated) or stretched to fill the viewport.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ParallaxLayer(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Camera camera, float factor, float mapWidth, float mapHeight)
    Creates a basic parallax layer with default settings.
    ParallaxLayer(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Camera camera, float factor, float mapWidth, float mapHeight, boolean tileHorizontally, boolean tileVertically, float tileWidth, float tileHeight, float offsetX, float offsetY)
    Creates a tiled parallax layer with custom offset.
    ParallaxLayer(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Camera camera, float factor, float mapWidth, float mapHeight, boolean tileHorizontally, boolean tileVertically, float tileWidth, float tileHeight, float offsetX, float offsetY, float scaleX, float scaleY)
    Creates a fully customizable parallax layer.
    ParallaxLayer(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Camera camera, float factor, float mapWidth, float mapHeight, float offsetX, float offsetY)
    Creates a parallax layer with custom offset.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    render(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
    Renders this parallax layer to the screen.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ParallaxLayer

      public ParallaxLayer(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Camera camera, float factor, float mapWidth, float mapHeight)
      Creates a basic parallax layer with default settings. The layer will be stretched and use default scaling (1.0).
      Parameters:
      texture - The texture to display
      camera - The camera to track for parallax calculations
      factor - The parallax factor (0.0 = static, 1.0 = moves with camera)
      mapWidth - The total width of the game map
      mapHeight - The total height of the game map
    • ParallaxLayer

      public ParallaxLayer(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Camera camera, float factor, float mapWidth, float mapHeight, float offsetX, float offsetY)
      Creates a parallax layer with custom offset. The layer will be stretched and use default scaling (1.0).
      Parameters:
      texture - The texture to display
      camera - The camera to track for parallax calculations
      factor - The parallax factor (0.0 = static, 1.0 = moves with camera)
      mapWidth - The total width of the game map
      mapHeight - The total height of the game map
      offsetX - Horizontal offset in world units
      offsetY - Vertical offset in world units
    • ParallaxLayer

      public ParallaxLayer(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Camera camera, float factor, float mapWidth, float mapHeight, boolean tileHorizontally, boolean tileVertically, float tileWidth, float tileHeight, float offsetX, float offsetY)
      Creates a tiled parallax layer with custom offset. The texture will be repeated according to the tiling parameters.
      Parameters:
      texture - The texture to display
      camera - The camera to track for parallax calculations
      factor - The parallax factor (0.0 = static, 1.0 = moves with camera)
      mapWidth - The total width of the game map
      mapHeight - The total height of the game map
      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
    • ParallaxLayer

      public ParallaxLayer(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.graphics.Camera camera, float factor, float mapWidth, float mapHeight, boolean tileHorizontally, boolean tileVertically, float tileWidth, float tileHeight, float offsetX, float offsetY, float scaleX, float scaleY)
      Creates a fully customizable parallax layer. This is the master constructor that all other constructors delegate to.
      Parameters:
      texture - The texture to display
      camera - The camera to track for parallax calculations
      factor - The parallax factor (0.0 = static, 1.0 = moves with camera)
      mapWidth - The total width of the game map
      mapHeight - The total height of the game map
      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 (1.0 = original size)
      scaleY - Vertical scale factor (1.0 = original size)
  • Method Details

    • render

      public void render(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
      Renders this parallax layer to the screen. Calculates the appropriate position based on camera movement and parallax factor, then renders either as tiles or stretched based on configuration.
      Parameters:
      batch - The sprite batch to use for rendering