Hello there
I've been trying to create a solution for the ability to regulate at which layer the sprite will be drawn. Basically I created a class that does the same thing as sf::RenderWindow does, except setting the priority in the rendering.
Here is how it looks:
winhndl.h:
#pragma once
#include <SFML/Graphics.hpp>
#include <vector>
class WindowHandler
{
private:
sf::RenderWindow win;
std::vector<sf::Drawable> buffer[5];
public:
WindowHandler(const sf::RenderWindow& window);
void draw(const sf::Drawable& targ, int priority); // 0 - top priority, 4 - bottom priority
void render();
void setView(const sf::View& camera);
};
winhndl.cpp:
#include "winhndl.h"
WindowHandler::WindowHandler(const sf::RenderWindow& window)
{
win.create(window.getSystemHandle(), window.getSettings());
}
void WindowHandler::draw(const sf::Drawable& targ, int priority)
{
buffer[priority].push_back(targ);
}
void WindowHandler::render()
{
win.clear();
for(int i = 4; i >= 0; i--)
{
for(const auto& t : buffer[i])
{
win.draw(t);
}
buffer[i].clear();
}
win.display();
}
void WindowHandler::setView(const sf::View& camera)
{
win.setView(camera);
}
But when I build the project I am met with the two errors:
invalid new-expression of abstract class type 'sf::Drawable'
static assertion failed: result type must be constructible from input type
I am not even sure if I have chosen the right datatype for buffer array. I have been stuck on this problem for a few days now.
Thanks in advance