Im trying to do a vector of struct elements to draw them in RenderWindow;
my struct for non-ui objects:
struct element{
sf::Texture texture;
sf::Sprite sprite;
sf::IntRect rect;
sf::Text text;
};my struct for ui objects:
struct uiElement: element{
sf::Text text;
bool clickable;
};Im adding elements like that:
std::vector<uiElement> ui;
uiElement el;
el.texture.loadFromFile("../res/textures/background.jpg");
ui.push_back(el);
ui.back().sprite.setTexture(ui.back().texture);and it works!But, only if my
"std::vector<uiElement> ui;" has one element;
when i try to add more with cycle:
for (int i = 0;i < 4;i++){
uiElement btn;
btn.texture.loadFromFile("../res/textures/button.png");
ui.push_back(btn);
ui.back().sprite.setTexture(ui.back().texture);
}draws only last object in my
"std::vector<uiElement> ui;" and the other are just white
my drawing part of code:
for (auto & element : ui){
window.draw(element.sprite);
}How can I fix it??
thanks in advance