mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Don't needlesly call getSize() twice while setting texture
This commit is contained in:
parent
aa81cae6cf
commit
b939c794fb
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user