SFML community forums

General => General discussions => Topic started by: tsarek on January 10, 2009, 05:10:00 pm

Title: Bug in void sf:: Sprite:: SetImage (const Image & Img)
Post by: tsarek on January 10, 2009, 05:10:00 pm
Sorry for the bad English.

Noticed a bug, when using void sf:: Sprite:: SetImage (const Image & Img).
Using SFML 1.3, openSuse 11.0, freeglut 060903-133.1, mesa 7.0.3-35.1, ati radeon 9660

If the previous sprite size is less than the new image size, the new image cropped to fit the sprite size.

Example:

Code: [Select]

sf::Image image1;
image.LoadFromFile( "image1.png" );
sf::Image image2;
image.LoadFromFile( "image2.png" ); // Size of image1 is less than size of image2

sf::Sprite sprite( image1 );
...
...
sprite.SetImage( image2 ); // Sprite size not change


Thanks for the SFML library.
Title: Bug in void sf:: Sprite:: SetImage (const Image & Img)
Post by: Hiura on January 10, 2009, 05:35:57 pm
That's not a bug. It runs the way Laurent wanted.
Title: Bug in void sf:: Sprite:: SetImage (const Image & Img)
Post by: tsarek on January 10, 2009, 06:10:28 pm
Why?

Code: [Select]
////////////////////////////////////////////////////////////
/// Set the image of the sprite
////////////////////////////////////////////////////////////
void Sprite::SetImage(const Image& Img)
{
    // If there was no source image before, adjust the rectangle
    // if (!myImage)    TODO  comment this and all right
        SetSubRect(IntRect(0, 0, Img.GetWidth(), Img.GetHeight()));

    // Assign the new image
    myImage = &Img;
}
Title: Bug in void sf:: Sprite:: SetImage (const Image & Img)
Post by: Laurent on January 10, 2009, 06:15:33 pm
Because:
http://www.sfml-dev.org/forum/viewtopic.php?t=821
Title: Bug in void sf:: Sprite:: SetImage (const Image & Img)
Post by: tsarek on January 10, 2009, 06:32:20 pm
Hm, when paint in a loop of tiles of various sizes to better initialize the same sprite different picture than each time to create a new sprite.
Please, write in the docs, that the sprites have constant size.
I have long searched for the cause, has not yet looked for source of library.
Title: Bug in void sf:: Sprite:: SetImage (const Image & Img)
Post by: tsarek on January 10, 2009, 06:37:58 pm
And more.
If the new picture is larger, sometimes around the sprites appear color artifacts.
It may be coincidence  to check the size of pictures in SetImage?
Title: Bug in void sf:: Sprite:: SetImage (const Image & Img)
Post by: Laurent on January 10, 2009, 06:48:11 pm
Quote
Please, write in the docs, that the sprites have constant size.

So I'd have to do this for every function of sf::Sprite, as they also don't change its subrect. And I would even have to specify that every accessor doesn't change the other attributes... ;)