Heyho, i managed to code a script which creates a rectangle when i press a key on my keyboard. This rectangle is call Item and gets created by a class. I tried to make wevy texture path global ind Textures.h and Textures.cpp to check if the texture or the texturepath loses runtime during creating and drawing the sprites. Somehow the menubuttons have the textures which i have defined. But the item in the key pressed script gots created but id doesnt have the defined texture
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::R) {
std::string test_item = "D:/Coding/Projects/Factory Game/Textures/Raw Ores/Raw Bronze.png";
Item Test_Item = Item("TestItem", "TestItem", 200, 200, 64, 64, true, test_path, false, 100, 100, 1);
std::string test_item_index = "1";
Item_Con.addItem(test_item_index, Test_Item);
}
I splited the item class into Class.h and Class.cpp:
Item::Item(const std::string& ID, const std::string& onclick_name, int positionX, int positionY, int sizeX, int sizeY, bool visibility,
const std::string& texturepath, bool dragable, int durability, int quality, int amount)
: ID(ID), onclick_name(onclick_name), positionX(positionX), positionY(positionY), sizeX(sizeX), sizeY(sizeY), visibility(visibility),
texturepath(texturepath), dragable(dragable), durability(durability), quality(quality), amount(amount){
if (!texture.loadFromFile(this->texturepath)) {
return;
}
sprite.setTexture(texture);
}