SFML community forums

Help => Graphics => Topic started by: barnack on May 13, 2019, 06:42:15 pm

Title: Scaling Sprite to integer sizes
Post by: barnack on May 13, 2019, 06:42:15 pm
Hi,
is there any way to force the size of a sprite to be rounded after scaling? I didn't find anything except a "setSize" that existed in previous SFML versions...
Title: Re: Scaling Sprite to integer sizes
Post by: Elias Daler on May 13, 2019, 07:24:21 pm
It's very strange that this function doesn't exist indeed.
The workaround is to use sf::RectangleShape, I guess.

I wonder why it was removed.
Title: Re: Scaling Sprite to integer sizes
Post by: Laurent on May 13, 2019, 08:07:03 pm
Because setSize is really just setScale(size / textureRect.size).
Title: Re: Scaling Sprite to integer sizes
Post by: Elias Daler on May 13, 2019, 09:38:10 pm
Yeah, but you can get a ton of rounding errors because of division/multiplication.
Title: Re: Scaling Sprite to integer sizes
Post by: Laurent on May 13, 2019, 10:14:11 pm
If so, setSize did not solve anything ;)
Title: Re: Scaling Sprite to integer sizes
Post by: Elias Daler on May 13, 2019, 10:21:17 pm
Ah, I remembered how Transformable stores scale and later computes transform matrix.
Yeah, in this case getting rounding errors is inevitable.

OP should probably use RectangleShape for precise integer sprite sizes, yeah.