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

Public Member Functions

 Layer (std::string name)
 Construct a Layer object. More...
 
 Layer (const Layer &)=delete
 
 Layer (Layer &&)=default
 
Layeroperator= (const Layer &)=delete
 
Layeroperator= (Layer &&)=default
 
void clear ()
 Removes all the drawables.
 
template<typename T , typename = std::enable_if_t<std::is_base_of_v<sf::Drawable, T>>>
void add (const T &dr)
 Add a drawable to the Layer. More...
 
template<typename T , typename = std::enable_if_t<std::is_pointer_v<T>>, typename = std::enable_if_t<std::is_base_of_v<sf::Drawable, std::remove_pointer_t<T>>>>
void add (T dr)
 
template<typename T , typename = std::enable_if_t<std::is_pointer_v<T>>, typename = std::enable_if_t<std::is_base_of_v<sf::Drawable, std::remove_pointer_t<T>>>>
void addRaw (T dr)
 Add a drawable to the layer The pointer is not managed by the Layer, and you have to delete it manually after removing it from the Layer. More...
 
template<typename T , typename = std::enable_if_t<std::is_base_of_v<sf::Drawable, T>>>
void remove (const T &dr)
 Remove a drawable from the Layer. More...
 
template<typename T , typename = std::enable_if_t<std::is_pointer_v<T>>, typename = std::enable_if_t<std::is_base_of_v<sf::Drawable, std::remove_pointer_t<T>>>>
void remove (T dr)
 
auto allDrawables () const -> const std::vector< const sf::Drawable *> &
 Get a vector of all drawables added to the Layer. More...
 
auto getDrawablePosition (const sf::Drawable *dr) const -> sf::Vector2f
 
auto getDrawableBounds (const sf::Drawable *dr) const -> sf::FloatRect
 
void ySort ()
 Sorts Layer drawables by their Y coordinate. More...
 
auto getName () const -> const std::string &
 Get the name of the Layer. More...
 

Detailed Description

Definition at line 26 of file core/Layer.hpp.

Constructor & Destructor Documentation

◆ Layer()

ns::Layer::Layer ( std::string  name)
explicit

Construct a Layer object.

A Layer is a container that keep pointers to drawables objects. It is used to organize the order of drawing of multiple drawables.

Parameters
nameLayer name

Member Function Documentation

◆ add()

template<typename T , typename >
void ns::Layer::add ( const T &  dr)

Add a drawable to the Layer.

Parameters
drawableDrawable to add

Definition at line 113 of file core/Layer.hpp.

◆ addRaw()

template<typename T , typename , typename >
void ns::Layer::addRaw ( dr)

Add a drawable to the layer The pointer is not managed by the Layer, and you have to delete it manually after removing it from the Layer.

Parameters
drawablePointer to the drawable to add

Definition at line 138 of file core/Layer.hpp.

◆ allDrawables()

auto ns::Layer::allDrawables ( ) const -> const std::vector< const sf::Drawable *> &

Get a vector of all drawables added to the Layer.

Returns
Vector of const sf::Drawable*

◆ getName()

auto ns::Layer::getName ( ) const -> const std::string &

Get the name of the Layer.

Returns
Name of the Layer

◆ remove()

template<typename T , typename >
void ns::Layer::remove ( const T &  dr)

Remove a drawable from the Layer.

Parameters
drawableDrawable to remove

Definition at line 143 of file core/Layer.hpp.

◆ ySort()

void ns::Layer::ySort ( )

Sorts Layer drawables by their Y coordinate.

ySort can be used to perform Z ordring for top down games


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