#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
#include <vector>
using namespace sf; using namespace std;
class Obj {
public:
string path;
Sprite sprite;
Texture texture;
Obj(string Path) : path(Path)
{
if (!texture.loadFromFile(Path))
{
cout << "load texture fail" << endl;
}
sprite.setTexture(texture);
}
Obj(const Obj& o): path(o.path), texture(o.texture)
{
this->sprite.setTexture(this->texture);
}
Obj(Obj&& o): path(o.path)
{
swap(this->texture, o.texture);
this->sprite.setTexture(this->texture);
}
};
vector<Obj> obj;
int countObjects = 0;
void createObject(string Path){
countObjects++;
obj.emplace_back(Path);
}
int main() {
RenderWindow window(VideoMode(800, 600), L"name", Style::Default);
createObject("res/obj1.png");
createObject("res/obj2.png");
Event event;
while (window.isOpen()){
while (window.pollEvent(event)) {
if (event.type == Event::Closed ||
(event.type == sf::Event::KeyPressed && event.key.code == Keyboard::Escape))
window.close();
}
window.clear();
window.draw(obj[0].sprite);
window.display();
}
return 0;
}
I2luY2x1ZGUgPFNGTUwvR3JhcGhpY3MuaHBwPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDx2ZWN0b3I+Cgp1c2luZyBuYW1lc3BhY2Ugc2Y7IHVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyBPYmogewpwdWJsaWM6CglzdHJpbmcgcGF0aDsKCVNwcml0ZSBzcHJpdGU7CglUZXh0dXJlIHRleHR1cmU7CglPYmooc3RyaW5nIFBhdGgpIDogcGF0aChQYXRoKQoJewoJCWlmICghdGV4dHVyZS5sb2FkRnJvbUZpbGUoUGF0aCkpCgkJewoJCQljb3V0IDw8ICJsb2FkIHRleHR1cmUgZmFpbCIgPDwgZW5kbDsKCQl9CgkJc3ByaXRlLnNldFRleHR1cmUodGV4dHVyZSk7Cgl9CgkKCU9iaihjb25zdCBPYmomIG8pOiBwYXRoKG8ucGF0aCksIHRleHR1cmUoby50ZXh0dXJlKQogICAgewogICAgICAgIHRoaXMtPnN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