I'm trying to make a vector of a custom class (Called "WorldObject").
The WorldObject class is defined here:
class WorldObject : public sf::Drawable {
private:
sf::Texture _texture;
int spriteWidth;
int spriteHeight;
int xPos;
int yPos;
public:
WorldObject(std::string filename, int width, int height, int _xPos, int _yPos);
sf::Sprite _sprite;
~WorldObject();
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
sf::FloatRect getCollisionBox();
};
The initialization class is defined here:
WorldObject::WorldObject(std::string filename, int width, int height, int _xPos, int _yPos) {
if(_texture.loadFromFile(filename)) {
_sprite.setTexture(_texture);
}
spriteWidth = width;
spriteHeight = height;
xPos = _xPos;
yPos = _yPos;
_sprite.setPosition(xPos, yPos);
}
And the vector code is defined here (It is a vector<WorldObject>):
worldObjects.push_back({name, width, height, x, y});
I've also used worldObjects.push_back(WorldObject(name, width, height, x, y));
where name is the filename (In this case, test_object.png), width is the width of the object (192 px), height is the height of the object (192 px), x is the x position (300) and y is the y position (400) in the SFML window (800px, 600px).
I'm trying to load test_object.png. For some kind of reason, it ALWAYS ends up creating a white square instead, in the correct position and with the right dimensions, though.
I can't figure out why this happens. I've tried passing "name" by reference, by value, trying to use a vector<Texture> and substituting filename's std::string type by a sf::Texture one without any avail.
Thanks @super for making me remember that the Texture doesn't load and that the file name is correct and that the file exists