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

Author Topic: Bug in void sf:: Sprite:: SetImage (const Image & Img)  (Read 5206 times)

0 Members and 1 Guest are viewing this topic.

tsarek

  • Newbie
  • *
  • Posts: 4
    • View Profile
Bug in void sf:: Sprite:: SetImage (const Image & Img)
« 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.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Bug in void sf:: Sprite:: SetImage (const Image & Img)
« Reply #1 on: January 10, 2009, 05:35:57 pm »
That's not a bug. It runs the way Laurent wanted.
SFML / OS X developer

tsarek

  • Newbie
  • *
  • Posts: 4
    • View Profile
Bug in void sf:: Sprite:: SetImage (const Image & Img)
« Reply #2 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;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

tsarek

  • Newbie
  • *
  • Posts: 4
    • View Profile
Bug in void sf:: Sprite:: SetImage (const Image & Img)
« Reply #4 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.

tsarek

  • Newbie
  • *
  • Posts: 4
    • View Profile
Bug in void sf:: Sprite:: SetImage (const Image & Img)
« Reply #5 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Bug in void sf:: Sprite:: SetImage (const Image & Img)
« Reply #6 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... ;)
Laurent Gomila - SFML developer