NasNas
An intuitive and beginner friendly 2D game framework for C++
Public Member Functions | Friends | List of all members
ns::Camera Class Reference
Inheritance diagram for ns::Camera:
ns::ShaderHolder

Public Member Functions

 Camera (std::string name, int render_order)
 Construct a Camera object. More...
 
 Camera (const Camera &)=delete
 
 Camera (Camera &&)=default
 
Cameraoperator= (const Camera &)=delete
 
Cameraoperator= (Camera &&)=default
 
void reset (int x, int y, int w, int h)
 Reset Camera size and position. More...
 
void reset (const sf::Vector2i &position, const sf::Vector2i &size)
 Reset Camera size and position. More...
 
void reset (const ns::IntRect &rect)
 Reset Camera size and position. More...
 
void resetViewport (float x, float y, float w, float h)
 Reset Camera viewport. More...
 
void resetViewport (const sf::Vector2f &position, const sf::Vector2f &size)
 Reset Camera viewport. More...
 
void resetViewport (const sf::FloatRect &rect)
 Reset Camera viewport. More...
 
auto getViewport () const -> const ns::FloatRect &
 
auto hasScene () -> bool
 Is the Camera looking at a Scene ? More...
 
void lookAt (Scene &scene)
 Tell the Camera to look at a Scene. More...
 
auto isVisible () const -> bool
 Is the Camera visible ? More...
 
void setVisible (bool value)
 Show or hide the Camera content. More...
 
void follow (sf::Transformable &transformable)
 Follow an entity, Camera position will be updated accordingly automatically. More...
 
void unfollow ()
 
auto getRenderOrder () const -> int
 Get render order of the Camera. More...
 
auto getFramesDelay () const -> unsigned int
 
void setFramesDelay (unsigned int value)
 Set the frame delay. More...
 
void setLimitsRect (const ns::IntRect &rectangle)
 Sets Camera move limits. More...
 
auto getPosition () const -> sf::Vector2f
 Get Camera position in world's coordinates. More...
 
auto getFolloweePosition () const -> const sf::Vector2f &
 
auto getLeft () const -> float
 Get Camera left position in world's coordinates. More...
 
void setLeft (float value)
 Set Camera left position in world's coordinates. More...
 
auto getRight () const -> float
 Get Camera right position in world's coordinates. More...
 
void setRight (float value)
 Set Camera right position in world's coordinates. More...
 
auto getTop () const -> float
 Get Camera top position in world's coordinates. More...
 
void setTop (float value)
 Set Camera top position in world's coordinates. More...
 
auto getBottom () const -> float
 Get Camera bottom position in world's coordinates. More...
 
void setBottom (float value)
 Set Camera bottom position in world's coordinates. More...
 
auto getGlobalBounds () const -> ns::FloatRect
 Get camera global bounds. More...
 
void update ()
 Updates Camera position if following an entity.
 
- Public Member Functions inherited from ns::ShaderHolder
void setShader (sf::Shader *shader)
 Set the shader to be applied when rendering. More...
 
auto getShader () const -> sf::Shader *
 Get the current Shader. More...
 
void toggleShader ()
 Toggle shader.
 
void clearShader ()
 Remove the shader. More...
 

Friends

class App
 

Detailed Description

Definition at line 22 of file Camera.hpp.

Constructor & Destructor Documentation

◆ Camera()

ns::Camera::Camera ( std::string  name,
int  render_order 
)

Construct a Camera object.

Parameters
nameName of the Camera object
render_orderRender order of the Camera object

Member Function Documentation

◆ follow()

void ns::Camera::follow ( sf::Transformable &  transformable)

Follow an entity, Camera position will be updated accordingly automatically.

Parameters
drawableDrawable object to follow

◆ getBottom()

auto ns::Camera::getBottom ( ) const -> float

Get Camera bottom position in world's coordinates.

Returns
Camera bottom boundary position

◆ getFramesDelay()

auto ns::Camera::getFramesDelay ( ) const -> unsigned int

Get delay in position update over the followed entity

Returns
Frame delay

◆ getGlobalBounds()

auto ns::Camera::getGlobalBounds ( ) const -> ns::FloatRect

Get camera global bounds.

Returns
Camera rectangle view

◆ getLeft()

auto ns::Camera::getLeft ( ) const -> float

Get Camera left position in world's coordinates.

Returns
Camera left boundary position

◆ getPosition()

auto ns::Camera::getPosition ( ) const -> sf::Vector2f

Get Camera position in world's coordinates.

Returns
Camera position

◆ getRenderOrder()

auto ns::Camera::getRenderOrder ( ) const -> int

Get render order of the Camera.

0 is rendered first, then 1, then 2 ...

Returns
Camera render order

◆ getRight()

auto ns::Camera::getRight ( ) const -> float

Get Camera right position in world's coordinates.

Returns
Camera right boundary position

◆ getTop()

auto ns::Camera::getTop ( ) const -> float

Get Camera top position in world's coordinates.

Returns
Camera top boundary position

◆ hasScene()

auto ns::Camera::hasScene ( ) -> bool

Is the Camera looking at a Scene ?

Returns
True if Camera looking at a Scene

◆ isVisible()

auto ns::Camera::isVisible ( ) const -> bool

Is the Camera visible ?

Returns
True if the Camera is visible

◆ lookAt()

void ns::Camera::lookAt ( Scene scene)

Tell the Camera to look at a Scene.

Parameters
scenePointer to a Scene object

◆ reset() [1/3]

void ns::Camera::reset ( int  x,
int  y,
int  w,
int  h 
)

Reset Camera size and position.

Parameters
xNew X position
yNew Y position
wNew width
hNew height

◆ reset() [2/3]

void ns::Camera::reset ( const sf::Vector2i &  position,
const sf::Vector2i &  size 
)

Reset Camera size and position.

Parameters
positionNew position
sizeNew size

◆ reset() [3/3]

void ns::Camera::reset ( const ns::IntRect rect)

Reset Camera size and position.

Parameters
rectNew view rectangle {position, size}

◆ resetViewport() [1/3]

void ns::Camera::resetViewport ( float  x,
float  y,
float  w,
float  h 
)

Reset Camera viewport.

Viewport defines how much space Camera content should take on the window and where it is placed. Coordinates in percentage. e.g. : 0 = 0% of the window 0.5 = 50% of the window 1 = 100% of the window

Parameters
xNew viewport X pos
yNew viewport Y pos
wNew viewport width
hNew viewport height

◆ resetViewport() [2/3]

void ns::Camera::resetViewport ( const sf::Vector2f &  position,
const sf::Vector2f &  size 
)

Reset Camera viewport.

Parameters
positionNew viewport position
sizeNew viewport size

◆ resetViewport() [3/3]

void ns::Camera::resetViewport ( const sf::FloatRect &  rect)

Reset Camera viewport.

Parameters
rectNew viewport

◆ setBottom()

void ns::Camera::setBottom ( float  value)

Set Camera bottom position in world's coordinates.

Parameters
valueNew bottom boundary position

◆ setFramesDelay()

void ns::Camera::setFramesDelay ( unsigned int  value)

Set the frame delay.

A delay of N means the Camera will need N frames to go to the followed entity position. Allows smooth camera movements

Parameters
valueFrame delay

◆ setLeft()

void ns::Camera::setLeft ( float  value)

Set Camera left position in world's coordinates.

Parameters
valueNew left boundary position

◆ setLimitsRect()

void ns::Camera::setLimitsRect ( const ns::IntRect rectangle)

Sets Camera move limits.

Parameters
rectangleLimits rectangle

◆ setRight()

void ns::Camera::setRight ( float  value)

Set Camera right position in world's coordinates.

Parameters
valueNew right boundary position

◆ setTop()

void ns::Camera::setTop ( float  value)

Set Camera top position in world's coordinates.

Parameters
valueNew top boundary position

◆ setVisible()

void ns::Camera::setVisible ( bool  value)

Show or hide the Camera content.

Parameters
value

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