I'm trying to make a sprite vector but the first few elements always show a white square. The variables are contained in the TileRPG class to then be used in the main.cpp tile.cpp
void TileRPG::draw(int id, float x, float y, sf::RenderWindow& window) {
m_sprite[id].setPosition(sf::Vector2f(x, y));
window.draw(m_sprite[id]);
}
TileRPG::TileRPG() {
std::ifstream file { "data/tileRPGList.rf" };
std::string line{ "" }, access { "" };
sf::Texture texture;
sf::Sprite sprite;
unsigned int i = 0;
while (std::getline(file, line)) {
m_texture.push_back(texture);
m_sprite.push_back(sprite);
access = "data/" + line;
m_texture[i].loadFromFile(access);
m_sprite[i].setTexture(m_texture[i]);
i++;
}
}
tile.hpp
class Tile {
protected:
std::vector<sf::Texture> m_texture;
std::vector<sf::Sprite> m_sprite;
};
class TileRPG : public Tile {
public:
TileRPG();
void draw(int id, float x, float y, sf::RenderWindow& window);
};
Aucun commentaire:
Enregistrer un commentaire