Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sprite] don't set default rect before the user provided one #1725

Merged
merged 2 commits into from
Jan 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/SFML/Graphics/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Sprite::Sprite(const Texture& texture) :
m_texture (NULL),
m_textureRect()
{
setTexture(texture);
setTexture(texture, true);
}


Expand All @@ -55,8 +55,10 @@ Sprite::Sprite(const Texture& texture, const IntRect& rectangle) :
m_texture (NULL),
m_textureRect()
{
setTexture(texture);
// Compute the texture area
setTextureRect(rectangle);
// Assign texture
setTexture(texture, false);
}


Expand All @@ -65,7 +67,10 @@ void Sprite::setTexture(const Texture& texture, bool resetRect)
{
// Recompute the texture area if requested, or if there was no valid texture & rect before
if (resetRect || (!m_texture && (m_textureRect == sf::IntRect())))
setTextureRect(IntRect(0, 0, texture.getSize().x, texture.getSize().y));
{
Vector2u size = texture.getSize();
setTextureRect(IntRect(0, 0, size.x, size.y));
}

// Assign the new texture
m_texture = &texture;
Expand Down