#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);
}
};
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+Cgp1c2luZyBuYW1lc3BhY2Ugc2Y7IHVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyBPYmogewpwdWJsaWM6CglzdHJpbmcgcGF0aDsKCVNwcml0ZSBzcHJpdGU7CglUZXh0dXJlIHRleHR1cmU7CglPYmooc3RyaW5nIFBhdGgpIDogcGF0aChQYXRoKQoJewoJCWlmICghdGV4dHVyZS5sb2FkRnJvbUZpbGUoUGF0aCkpCgkJewoJCQljb3V0IDw8ICJsb2FkIHRleHR1cmUgZmFpbCIgPDwgZW5kbDsKCQl9CgkJc3ByaXRlLnNldFRleHR1cmUodGV4dHVyZSk7Cgl9Cn07Cgp2ZWN0b3I8T2JqPiBvYmo7CgppbnQgY291bnRPYmplY3RzID0gMDsKCnZvaWQgY3JlYXRlT2JqZWN0KHN0cmluZyBQYXRoKXsKCWNvdW50T2JqZWN0cysrOwoJb2JqLmVtcGxhY2VfYmFjayhQYXRoKTsKfQoKCmludCBtYWluKCkgewoJUmVuZGVyV2luZG93IHdp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