SFML community forums

Help => Graphics => Topic started by: aNewHobby on May 14, 2012, 03:00:00 am

Title: How do you load a image into a sprite in SFML2? the old way dose not work?
Post by: aNewHobby on May 14, 2012, 03:00:00 am
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
Title: Re: How do you load a image into a sprite in SFML2? the old way dose not work?
Post by: eXpl0it3r on May 14, 2012, 07:48:41 am
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. ;)