Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Scaling Sprite to integer sizes  (Read 2390 times)

0 Members and 1 Guest are viewing this topic.

barnack

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Scaling Sprite to integer sizes
« 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...

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Scaling Sprite to integer sizes
« Reply #1 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.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Scaling Sprite to integer sizes
« Reply #2 on: May 13, 2019, 08:07:03 pm »
Because setSize is really just setScale(size / textureRect.size).
Laurent Gomila - SFML developer

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Scaling Sprite to integer sizes
« Reply #3 on: May 13, 2019, 09:38:10 pm »
Yeah, but you can get a ton of rounding errors because of division/multiplication.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Scaling Sprite to integer sizes
« Reply #4 on: May 13, 2019, 10:14:11 pm »
If so, setSize did not solve anything ;)
Laurent Gomila - SFML developer

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Scaling Sprite to integer sizes
« Reply #5 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.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

 

anything