Hi, I have a problem and I can not solve it...
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
#include <tuple>
enum class ID
{
Background,
Player
};
std::vector<std::tuple<ID, sf::Texture, sf::Sprite>> drawables;
void add(ID id, const std::string &path)
{
sf::Texture texture;
if(!texture.loadFromFile(path))
throw std::runtime_error("Could not load: " + path);
sf::Sprite sprite(texture);
drawables.push_back(std::make_tuple(id,texture,sprite));
}
int main()
{
add(ID::Background, "Data/Background.png");
sf::RenderWindow window(sf::VideoMode(500, 500), "Test");
window.setFramerateLimit(60);
while(window.isOpen())
{
window.clear();
window.draw(std::get<2>(drawables[0]));
window.display();
}
return 0;
}
I really don't get why this is not working, I think that the texture or sprite is somewhere copied and not used as a reference but i can not change the vector's tuple arguments to references or pointers because this makes errors :/