Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - trapped_in_a_corner

Pages: [1]
1
General / Texture wont load
« on: October 04, 2022, 03:11:46 pm »
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!

Pages: [1]