Package com.csse3200.game.components
Class CameraComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.CameraComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable
A component that manages a camera for rendering.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new CameraComponent with a default OrthographicCamera.CameraComponent
(com.badlogic.gdx.graphics.Camera camera) Creates a new CameraComponent with a specified camera. -
Method Summary
Modifier and TypeMethodDescriptionboolean
entityOnScreen
(Entity entity) Determines if the given entity is on the screencom.badlogic.gdx.graphics.Camera
com.badlogic.gdx.math.Matrix4
Gets the entity currently tracked by the camera.void
resize
(int screenWidth, int screenHeight, float gameWidth) com.badlogic.gdx.math.Vector2
screenPositionToWorldPosition
(com.badlogic.gdx.math.Vector2 screenPosition) Converts screen position vector to world position vectorvoid
setTrackEntity
(Entity trackEntity) Sets the entity to track by the camera.void
update()
Updates the camera's position based on the tracked entity's position.Methods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, read, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, write
-
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. -
getProjectionMatrix
public com.badlogic.gdx.math.Matrix4 getProjectionMatrix() -
getCamera
public com.badlogic.gdx.graphics.Camera getCamera() -
getTrackEntity
Gets the entity currently tracked by the camera.- Returns:
- The tracked entity.
-
setTrackEntity
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
Determines if the given entity is on the screen- Parameters:
entity
- : entity to be checked- Returns:
- true if on screen else false
-