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

Author Topic: Fitting Sprite to Window on Resize  (Read 6953 times)

0 Members and 1 Guest are viewing this topic.

Xander314

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://sfmlcoder.wordpress.com/
    • Email
Fitting Sprite to Window on Resize
« on: May 28, 2011, 12:13:20 pm »
I was resizing my sprite to fit my window using:
Code: [Select]
Sprite.Scale((float)Window.GetWidth()/(float)Sprite.GetImage()->GetWidth(), (float)Window.GetHeight()/(float)Sprite.GetImage()->GetHeight());
and then
Code: [Select]
Sprite.Resize(Window.GetWidth(), Window.GetHeight());
when the sf::Event::Resize event is dispatched.

However, I have noticed that when I resize the window smaller than the video mode, the sprite no longer fits the screen. Why is this? And is there anything I can do about it?

Also, for the sf::Event::Resize event, what is the relevance of the values Event::Size::Width and Event::Size::Height. Surely they are the same as the values returned by Window::GetWidth() and Window::GetHeight()?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Fitting Sprite to Window on Resize
« Reply #1 on: May 28, 2011, 12:18:12 pm »
When a window is resized, its view doesn't change which means that things are already automatically scaled.

So you just need to resize your sprite at the beginning, no need to adjust it on resize events.

Quote
Also, for the sf::Event::Resize event, what is the relevance of the values Event::Size::Width and Event::Size::Height. Surely they are the same as the values returned by Window::GetWidth() and Window::GetHeight()?

Of course they are ;)
Laurent Gomila - SFML developer

Xander314

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://sfmlcoder.wordpress.com/
    • Email
Fitting Sprite to Window on Resize
« Reply #2 on: May 28, 2011, 12:31:46 pm »
Strictly speaking therefore, should my resize operation be this instread:
Code: [Select]
Sprite.Resize(VideoMode.X, VideoMode.Y);?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Fitting Sprite to Window on Resize
« Reply #3 on: May 28, 2011, 02:15:46 pm »
Yes.
Laurent Gomila - SFML developer

Xander314

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://sfmlcoder.wordpress.com/
    • Email
Fitting Sprite to Window on Resize
« Reply #4 on: May 28, 2011, 02:16:34 pm »
Thanks for your help and speedy replies as usual :D