SFML community forums

Help => Graphics => Topic started by: bobbyport on June 28, 2009, 04:49:18 am

Title: SetImage
Post by: bobbyport on June 28, 2009, 04:49:18 am
When I .SetImage()

It seems the sprite's width and height remain the same.... Must I manually change the dimensions to match the new image, or is there a way for automation?
Title: SetImage
Post by: bobbyport on June 28, 2009, 05:28:48 am
Nevermind, I guess I must set manually with: sprite::SetSubRect()
Title: SetImage
Post by: K-Bal on June 28, 2009, 10:12:21 am
Quote from: "bobbyport"
Nevermind, I guess I must set manually with: sprite::SetSubRect()


Thats how it is ;)
Title: SetImage
Post by: nitram_cero on July 06, 2009, 11:10:10 pm
I also hated that  :lol:

You can also do a
Code: [Select]
spr.SetImage(Image());
spr.SetImage(theImage);
Title: Re: SetImage
Post by: Nexus on July 07, 2009, 11:09:07 am
Quote from: "bobbyport"
Must I manually change the dimensions to match the new image, or is there a way for automation?
There is always a way for automation. ;)

Code: [Select]
void AdaptImage(sf::Sprite& Sprite, const sf::Image& NewImage)
{
    Sprite.SetImage(NewImage);
    Sprite.SetSubRect(sf::IntRect(0, 0, NewImage.GetWidth(), NewImage.GetHeight()));
}