Gamedev Framework (gf)  0.5.0
A C++11 framework for 2D games
Public Member Functions | List of all members
gf::Drawable Class Referenceabstract

Abstract base class for objects that can be drawn to a render window. More...

#include <gf/Drawable.h>

Inheritance diagram for gf::Drawable:
Inheritance graph
[legend]

Public Member Functions

virtual ~Drawable ()
 Virtual desctructor. More...
 
virtual void draw (RenderTarget &target, RenderStates states)=0
 Draw the object to a render target. More...
 

Detailed Description

Abstract base class for objects that can be drawn to a render window.

gf::Drawable is a very simple base class that allows objects of derived classes to be drawn to a sf::RenderTarget.

All you have to do in your derived class is to override the draw() virtual function.

Note that inheriting from gf::Drawable is not mandatory, but it allows this nice syntax target.draw(object) rather than object.draw(target), which is more consistent with other classes.

Example:

class MyDrawable : public gf::Drawable {
public:
...
virtual void draw(gf::RenderTarget& target, gf::RenderStates states) override {
// You can draw other high-level objects
target.draw(m_sprite, states);
// ... or use the low-level API
states.texture = &m_texture;
target.draw(m_vertices, states);
}
private:
gf::Sprite m_sprite;
gf::Texture m_texture;
gf::VertexArray m_vertices;
};

Constructor & Destructor Documentation

◆ ~Drawable()

virtual gf::Drawable::~Drawable ( )
virtual

Virtual desctructor.

Member Function Documentation

◆ draw()

virtual void gf::Drawable::draw ( RenderTarget target,
RenderStates  states 
)
pure virtual

Draw the object to a render target.

This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.

Parameters
targetRender target to draw to
statesCurrent render states

Implemented in gf::UI, gf::Text, gf::Shape, gf::NinePatch, gf::TileLayer, gf::Sprite, gf::Curve, gf::VertexArray, gf::BufferedGeometry, gf::SquareGrid, gf::SpriteParticles, gf::ShapeParticles, gf::PostProcessing, gf::Logo, and gf::PointParticles.