Vigilante Game Framework  1.0.0.8
A 2D/3D C++ Game Framework using SFML.
Public Types | Public Member Functions | Public Attributes | List of all members
VCamera Class Reference

The 2D camera that renders the scene. More...

#include <VCamera.h>

Public Types

enum  CameraFollowMethod : unsigned char {
  LOCKON, TOPDOWN, PLATFORMER, ROOM,
  ROOMLERP
}
 The method of how the camera shall follow a specific VObject. More...
 

Public Member Functions

 VCamera ()
 The default constructor sets up the camera with a default view that is the size of the game's display.
 
 VCamera (sf::View &View)
 
void Follow (VObject *target, float deadzone=0.5f, CameraFollowMethod followmethod=LOCKON, float lead=0.0f, float lerp=0.0f)
 
void StopFollow ()
 Stop following a game object.
 
bool Shake (float intensity, float time=1.0f, std::function< void()> OnComplete=nullptr)
 
bool Shake (sf::Vector2f intensity, float time=1.0f, std::function< void()> OnComplete=nullptr)
 
bool Fade (sf::Color colour=sf::Color::Black, float time=1.0f, bool fadein=false, std::function< void()> OnComplete=nullptr)
 
bool Flash (sf::Color colour=sf::Color::Black, float time=1.0f, std::function< void()> OnComplete=nullptr)
 
void SetToBounds (bool bound, sf::FloatRect bounderies=sf::FloatRect())
 
void SetViewport (sf::FloatRect &viewport)
 
void Update (float dt)
 
void Render (sf::RenderTarget &RenderTarget)
 
void Reset ()
 
bool IsFading ()
 
bool IsFlashing ()
 
bool IsShaking ()
 
sf::View const & GetView ()
 
sf::View GetDefaultView ()
 

Public Attributes

sf::Vector2f Position
 The current position of the camera.
 
float Rotation = 0.0f
 The current angle of the camera.
 
float Zoom = 1.0f
 The current amount of zoom (default 1.0f) for the camera.
 
bool Active = true
 The camera is only used for rendering if Active is set to true.
 

Detailed Description

The 2D camera that renders the scene.

Member Enumeration Documentation

◆ CameraFollowMethod

enum VCamera::CameraFollowMethod : unsigned char

The method of how the camera shall follow a specific VObject.

Enumerator
LOCKON 

Locks on directly to the VObject with no lerp or lead.

TOPDOWN 

Locks onto the VObject with lerp and lead, best if a game has a top-down perspective.

PLATFORMER 

Locks onto the VObject with lerp and lead, but with no dead zone restrictions for moving up. Best if a game is a side-scrolling platformer.

ROOM 

Fixes to positions like a grid. best used for grid based levels where the screen size is evenly divisible to the world size.

ROOMLERP 

Same as Room, however instead of instantly changing positions, the camera will lerp to the next position.

Constructor & Destructor Documentation

◆ VCamera()

VCamera::VCamera ( sf::View &  View)
inline
Parameters
Viewthe sf::View that the Camera should use instead of the default one.

Member Function Documentation

◆ Fade()

bool VCamera::Fade ( sf::Color  colour = sf::Color::Black,
float  time = 1.0f,
bool  fadein = false,
std::function< void()>  OnComplete = nullptr 
)

Fade the screen the camera renders.

Parameters
colourThe colour the camera should fade from/to.
timeThe length of time for the camera to fade.
fadeinIf true, the camera will fade from the colour to the screen. If false it will do the reverse, as if to fade out from the screen.
OnCompleteA callback to call when the camera finishes fading.

◆ Flash()

bool VCamera::Flash ( sf::Color  colour = sf::Color::Black,
float  time = 1.0f,
std::function< void()>  OnComplete = nullptr 
)

Flash the screen the camera renders.

Parameters
colourThe colour the camera should flash to and from.
timeThe total length of time for the camera to flash.
OnCompleteA callback to call when the camera finishes flashing.

◆ Follow()

void VCamera::Follow ( VObject target,
float  deadzone = 0.5f,
CameraFollowMethod  followmethod = LOCKON,
float  lead = 0.0f,
float  lerp = 0.0f 
)

Set the camera to follow a specific VObject.

Parameters
targetThe object the camera must follow.
deadzoneThe dead zone area the camera should be restricted to.
followmethodThe follow method that the camera should use.
leadThe amount the camera should lead in front of the target.
lerpThe amount the camera should lerp towards the target.

◆ GetDefaultView()

sf::View VCamera::GetDefaultView ( )
Returns
The camera's current sf::View with default parameters.

◆ GetView()

sf::View const& VCamera::GetView ( )
inline
Returns
The camera's current sf::View.

◆ IsFading()

bool VCamera::IsFading ( )
inline
Returns
True if Fading.

◆ IsFlashing()

bool VCamera::IsFlashing ( )
inline
Returns
True if Flashing.

◆ IsShaking()

bool VCamera::IsShaking ( )
inline
Returns
True if Shaking.

◆ Render()

void VCamera::Render ( sf::RenderTarget &  RenderTarget)

Draws Camera for Flashing and Fading.

Parameters
RenderTargetthe game's sf::RenderTarget object to render data onto.

◆ Reset()

void VCamera::Reset ( )

Resets camera properties to default.

◆ SetToBounds()

void VCamera::SetToBounds ( bool  bound,
sf::FloatRect  bounderies = sf::FloatRect() 
)
inline
Parameters
boundIf true, the game will bound to the defined world bounderies.
bounderiesCustom bounderies to set the camera to, defaults to WorldBounds in VGlobal if none is set.

◆ SetViewport()

void VCamera::SetViewport ( sf::FloatRect &  viewport)
inline
Parameters
viewportsets the camera's view to display from a specific section of the viewport (default is FloatRect(0, 0, 1, 1)).

◆ Shake() [1/2]

bool VCamera::Shake ( float  intensity,
float  time = 1.0f,
std::function< void()>  OnComplete = nullptr 
)

Shake the camera.

Parameters
intensityThe amount as a decimal percentage (multiplied by the camera's width and height) to shake by.
timeThe length of time for the camera to shake for.
OnCompleteA callback to call when the camera finishes shaking.

◆ Shake() [2/2]

bool VCamera::Shake ( sf::Vector2f  intensity,
float  time = 1.0f,
std::function< void()>  OnComplete = nullptr 
)

Shake the camera.

Parameters
intensityThe amount as a decimal percentage (multiplied by the camera's width and height) to shake by.
timeThe length of time for the camera to shake for.
OnCompleteA callback to call when the camera finishes shaking.

◆ Update()

void VCamera::Update ( float  dt)

Updates the camera's position, rotation and zoom.

Parameters
dtDelta Time between the current and previous frame in the game.

The documentation for this class was generated from the following file: