Hello everyone, im beginner in SFML and i stuck in a problem. I want to refactor my code and wrote function that generate my sprites:
Sprite createSprite(const std::string path, float posX, float posY)
{
Image image;
image.loadFromFile(path);
Texture texture;
texture.loadFromImage(image);
Sprite sprite;
sprite.setTexture(texture);
sprite.setPosition(posX, posY);
return sprite;
}
Then i call it in main:
Sprite machineSprite = createSprite("images/machine.png", 20, 15);
then i call function to draw :
window.draw(machineSprite);
. And then i see next picture - my figures without images: (in attachments with white textures)
And before refactoring my code looked like this: (in attachments with normal graphics)
Image machineImage;
machineImage.loadFromFile("images/machine.png");
Texture machineTexture;
machineTexture.loadFromImage(machineImage);
Sprite machineSprite;
machineSprite.setTexture(machineTexture);
machineSprite.setPosition(20, 15);
What am I doing wrong, thanks in advance!