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

Author Topic: How do you load a image into a sprite in SFML2? the old way dose not work?  (Read 1480 times)

0 Members and 1 Guest are viewing this topic.

aNewHobby

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • Live 4 Ever Or Die Trying
I do not get how to load a image into a sprite...

        sf::Image iBackgrnd;
        if (!iBackgrnd.loadFromFile("board.png"))
                return EXIT_FAILURE;
        sf::Sprite backgrnd;
//      backgrnd.setImage(iBackgrnd); // - No longer works.... what do I do here instead?

Like this works...

        sf::Texture iBackgrnd;
        if (!iBackgrnd.loadFromFile("board.png"))
                return EXIT_FAILURE;
        sf::Sprite backgrnd;
        backgrnd.setTexture(iBackgrnd);

butthen.. what is Image used for? and how... the documentation says they are diffrent.. but I am not sure i understand how image is used now
« Last Edit: May 14, 2012, 03:13:41 am by aNewHobby »
Twitter: @Jyinkies
My Own Little Spot on the Net: - Live4everOrDieTrying.info (Blog)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
sf::Texture replaces the old sf::Image but since sf::Texture is now a real texture on the GPU it looses some properties. The most important factor is, that you can't edit a pixel directly on a sf::Texture but you can with a sf::Image.
But otherwise just use sf::Texture from now on. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/