Skip to content

Commit

Permalink
Don't needlesly call getSize() twice while setting texture
Browse files Browse the repository at this point in the history
  • Loading branch information
vfjpl committed Dec 9, 2020
1 parent c5dcaab commit 91fb6b6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/SFML/Graphics/Sprite.cpp
Expand Up @@ -55,7 +55,9 @@ Sprite::Sprite(const Texture& texture, const IntRect& rectangle) :
m_texture (NULL),
m_textureRect()
{
// 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

0 comments on commit 91fb6b6

Please sign in to comment.