Gamedev Framework (gf)  0.9.0
A C++14 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

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.


class MyDrawable : public gf::Drawable {
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);
gf::Sprite m_sprite;
gf::Texture m_texture;
gf::VertexArray m_vertices;

Constructor & Destructor Documentation

◆ ~Drawable()

virtual gf::Drawable::~Drawable ( )

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.

targetRender target to draw to
statesCurrent render states

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