Camera

Description:

Stand-alone class that controls the view matrix of game. Through the transform matrix, we can move all images, scale all images, and rotate all images to imitate what would happen if you were looking through a camera. This transform matrix is used in the spritebatch begin call in GameManager.

Relationships:

Members

  • Matrix transform - the transform matrix for the camera
  • Vector2 centerPosition - the center position of the camera
  • float maxCameraMove - this will be the max distance the camera can move per update which will make the camera "catch up" to the player

Methods

  • Reset
    • resets camera variables and sets position to the player
    • used whenever the camera needs to snap to the player's position immediately such as a level change
  • Camera
    • initializes variables and sets position to the player
  • Update
    • updates the camera to follow the player
    • when player possesses an enemy the camera will "catch up" to the player as opposed to instantly moving to the player
    • this will be done by getting the unit vector that points to the player's position from the camera's position, then scale it by either maxCameraMove or the distance between the camera and player, whichever is smallest
    • at the start of GameManager's draw it will grab the transform matrix and use it in spritebatch.begin().
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License