SFML community forums

Help => Graphics => Topic started by: txt on March 08, 2022, 11:15:57 am

Title: My sprite is cutted
Post by: txt on March 08, 2022, 11:15:57 am
Hi,

here is my code :

void corps::init(RenderWindow& w)
{
        texture.loadFromFile("image.png");
        texture.update(w);
        sprite.setTexture(texture);
        sprite.scale(Vector2f(0.5f, 0.5f));
}

void corps::afficher(RenderWindow& w)
{
        w.draw(cercle);
        w.draw(sprite);
        //supprimer le cerlce et mettre une image
}

My image is square logo, when i display it is cutted aat the top, it display all the image wide put only like 1/5 of the height image. I tried to change texture size but when i use IntRect... it give me an
error abort has been called

I just don't understand why is my image not displaying entirely and why resizing it give me error...
Title: Re: My sprite is cutted
Post by: eXpl0it3r on March 08, 2022, 11:30:37 am
You need to check the return value of loadFromFile.
Why do you load an image only to immediately replace it with the contents of your window?
Make sure you reset the texture rect when setting the sprite's texture (e.g. by passing true to the setTexture function.

If you application crashes, then it means you have a bug somewhere.
Use your debugger to find out what's going on.
Title: Re: My sprite is cutted
Post by: txt on March 08, 2022, 05:18:57 pm
Thanks a lot, i just had to remove texture.update line, i m french, english is very hard for me...
And thanks for others advices