So, my problem is this : I have a class called thing. The class basically creates a rectangle with a texture. When I'm drawing the rectangle on the window without using a vector, all works fine, but when I do, it takes the wrong texture (another texture from the same folder) even tho in the class it says nothing about that texture.
Here is the code :
Main.cpp#include <SFML/Graphics.hpp>
#include <iostream>
#include "thing.h"
#include <vector>
int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 720), "whatever", sf::Style::Close);
std::vector<thing> things;
things.emplace_back(thing());
sf::Texture textureanother1;
textureanother1.loadFromFile("textures/another1.png");
sf::Texture textureanother2;
textureanother2.loadFromFile("textures/another2.png");
sf::RectangleShape another1(sf::Vector2f(132.0f, 94.0f));
another1.setTexture(&textureanother1);
another1.setOrigin(66.0f, 94.0f);
another1.setPosition(500.0f, 680.0f);
sf::RectangleShape another2(sf::Vector2f(126.0f, 55.0f));
another2.setTexture(&textureanother2);
another2.setOrigin(63.0f, 55.0f);
another2.setPosition(500.0f, 605.0f);
while (window.isOpen())
{
sf::Event evnt;
while (window.pollEvent(evnt))
{
if (evnt.type == sf::Event::Closed)
{
window.close();
}
else
{
break;
}
}
window.draw(another1);
window.draw(things.at(0).thingItem);
window.draw(another2);
window.display();
}
return 0;
}
Thing.h
#pragma once
#include <SFML/Graphics.hpp>
class thing
{
public:
thing();
~thing();
sf::Texture thingTexture;
sf::RectangleShape thingItem;
};
Thing.cpp
#include "thing.h"
thing::thing()
{
thingTexture.loadFromFile("textures/sometexture.png");
thingItem.setTexture(&thingTexture);
thingItem.setSize(sf::Vector2f(16.25f, 99.25f));
thingItem.setOrigin(8.125f, 99.25f);
thingItem.setPosition(500.0f, 99.25f);
}
thing::~thing() = default;
Again,
ALL other rectangles except the one created with the class and a vector work fine. The one created with a class and a vector works fine
ONLY when it's used without a vector. What is wrong? There are no errors or warnings.
Instead of that : (which is showed when I use the class thing without a vector)
It shows that : (I used a vector, like in the code)
PS: I changed a bit names and deleted commens so you won't be confused by the strange words.