Class CameraComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.CameraComponent
All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable

public class CameraComponent extends Component
A component that manages a camera for rendering.
  • Constructor Details

    • CameraComponent

      public CameraComponent()
      Creates a new CameraComponent with a default OrthographicCamera.
    • CameraComponent

      public CameraComponent(com.badlogic.gdx.graphics.Camera camera)
      Creates a new CameraComponent with a specified camera.
      Parameters:
      camera - The camera to use for rendering.
  • Method Details

    • update

      public void update()
      Updates the camera's position based on the tracked entity's position.
      Overrides:
      update in class Component
    • getProjectionMatrix

      public com.badlogic.gdx.math.Matrix4 getProjectionMatrix()
    • getCamera

      public com.badlogic.gdx.graphics.Camera getCamera()
    • getTrackEntity

      public Entity getTrackEntity()
      Gets the entity currently tracked by the camera.
      Returns:
      The tracked entity.
    • setTrackEntity

      public void setTrackEntity(Entity trackEntity)
      Sets the entity to track by the camera.
      Parameters:
      trackEntity - The entity to track.
    • resize

      public void resize(int screenWidth, int screenHeight, float gameWidth)
    • screenPositionToWorldPosition

      public com.badlogic.gdx.math.Vector2 screenPositionToWorldPosition(com.badlogic.gdx.math.Vector2 screenPosition)
      Converts screen position vector to world position vector
      Parameters:
      screenPosition - Vector2 object with x, y screen position.
      Returns:
      vector of real world position
    • entityOnScreen

      public boolean entityOnScreen(Entity entity)
      Determines if the given entity is on the screen
      Parameters:
      entity - : entity to be checked
      Returns:
      true if on screen else false