diff --git a/include/SFML/Graphics/Sprite.hpp b/include/SFML/Graphics/Sprite.hpp index 4967d5640..ee771e941 100644 --- a/include/SFML/Graphics/Sprite.hpp +++ b/include/SFML/Graphics/Sprite.hpp @@ -66,10 +66,11 @@ public : //////////////////////////////////////////////////////////// /// Change the image of the sprite /// - /// \param image : New image + /// \param image : New image + /// \param adjustToNewSize : If true, the SubRect of the sprite will be adjusted to the size of the new image (false by default) /// //////////////////////////////////////////////////////////// - void SetImage(const Image& image); + void SetImage(const Image& image, bool adjustToNewSize = false); //////////////////////////////////////////////////////////// /// Set the sub-rectangle of the sprite inside the source image. diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index d6fd86141..52fb60b57 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -60,10 +60,14 @@ myIsFlippedY(false) //////////////////////////////////////////////////////////// /// Set the image of the sprite //////////////////////////////////////////////////////////// -void Sprite::SetImage(const Image& image) +void Sprite::SetImage(const Image& image, bool adjustToNewSize) { - // If there was no source image before and the new image is valid, adjust the source rectangle - if (!myImage && (image.GetWidth() > 0) && (image.GetHeight() > 0)) + // If there was no valid image before, force adjusting to the new image size + if (!myImage) + adjustToNewSize = true; + + // If we want to adjust the size and the new image is valid, we adjust the source rectangle + if (adjustToNewSize && (image.GetWidth() > 0) && (image.GetHeight() > 0)) { SetSubRect(IntRect(0, 0, image.GetWidth(), image.GetHeight())); }