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

Author Topic: My sprite is cutted  (Read 1627 times)

0 Members and 1 Guest are viewing this topic.

txt

  • Newbie
  • *
  • Posts: 2
    • View Profile
My sprite is cutted
« 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...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10822
    • View Profile
    • development blog
    • Email
Re: My sprite is cutted
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

txt

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: My sprite is cutted
« Reply #2 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

 

anything