Hello! This is my first post on SFML forums.
Recently, I have started a project in which I need a layer class, to group many drawables into one drawable. I have searched the forums, and I found some example code, which I tried to modify for my needs. However, I get strange compiler errors. Here is the code, first, then the errors:
Layer.h:
#include <SFML/Graphics.hpp>
class Layer : public sf::Drawable
{
public:
void AddDrawable(sf::Shape d);
protected:
typedef std::vector<sf::Shape> DrawableList;
virtual void Render(sf::RenderTarget &target);
private:
DrawableList myDrawables;
};
Layer.cpp:
#include "Layer.h"
void Layer::AddDrawable(sf::Shape d)
{
myDrawables.push_back(d);
}
void Layer::Render(sf::RenderTarget &target)
{
for(unsigned int f = 0; f < myDrawables.size(); f++)
{
target.Draw(*myDrawables[f]);
}
}
Trying to use Layer:
Layer a;
a.AddDrawable(sf::Shape::Rectangle(10, 10, 40, 40, sf::Color(255, 200, 0), 5, sf::Color(0, 255, 255)));
a.SetPosition(60, 50);
App.Draw(a);
The compiler errors I get are
-error: cannot declare variable 'a' to be of abstract type 'Layer'
-error: no matching function for call to 'Layer::AddDrawable(sf::Shape)'
Any help would be greatly appreciated!
Thank you!