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

Author Topic: sf::Sprite::GetWidth&GetHeight  (Read 3083 times)

0 Members and 1 Guest are viewing this topic.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
sf::Sprite::GetWidth&GetHeight
« on: January 21, 2010, 09:56:11 pm »
If you have a sprite that have assigned an image with (x, y) size, would be nice to have a function that returns the image size per sprite's scale.

Example:
Code: [Select]
Image img
Load img
Sprite spr
Assign img to spr
Scale spr 1/2, 1/2
-> Get spr width
-> Get spr height

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Sprite::GetWidth&GetHeight
« Reply #1 on: January 21, 2010, 10:15:31 pm »
Something like this?
Code: [Select]
sf::Vector2f GetScaledImageSize(const sf::Sprite& sprite)
{
return sf::Vector2f(
sprite.GetScale().x * sprite.GetImage()->GetWidth(),
sprite.GetScale().y * sprite.GetImage()->GetHeight());
}

I don't think this is so often required that an integration into SFML were really justified...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
sf::Sprite::GetWidth&GetHeight
« Reply #2 on: January 21, 2010, 10:29:15 pm »
Yeah, something like that :o

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Sprite::GetWidth&GetHeight
« Reply #3 on: January 21, 2010, 10:30:37 pm »
Yeah, that sounds a little weird. I can understand that you need the image size, or the sprite's size, but why the "image size scaled by the sprite's factor"??

If you need to get the sprite's size (which is the scaled subrect, not the entire image scaled), then you have sf::Sprite::GetSize.
Laurent Gomila - SFML developer