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

Author Topic: Window resize  (Read 2139 times)

0 Members and 1 Guest are viewing this topic.

robvleugel

  • Newbie
  • *
  • Posts: 29
    • View Profile
Window resize
« on: December 28, 2011, 05:55:49 pm »
Hello,

I'm writing a small game, I set up a window and placed some buttons on it. The buttons are sf::sprite objects using an sf::image of a button, some .PNG image file. At this moment, the buttons use a fixed X and Y position. I can click the button and everything works fine.

However, if the window is resized, the buttons stretch out, which is actually what I want to happen. However, the position checking uses the button's SF::image width and height to check for button presses, but these are no longer accurate after they are being resized.

My question is, why are the buttons being stretched? Although I want this to happen I'm not sure what actually causes it right now.
Is this happening automaticly for sf:sprite objects? And how could I solve my problem about the images being scaled, but not the sprite.GetPosition() and GetHeight()?

Do I need to use a virtual screen or something? And if so, what kind of class to I need to use for this virtual screen, another sf::RenderWindow or can I use a sf::image for that purpose?

Greetings,
Rob

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Window resize
« Reply #1 on: December 28, 2011, 06:58:49 pm »
Everything is stretched because the view doesn't change when the window is resized. So it still displays the same things (the same "region of the 2D world"), but in a bigger target (the resized window).

So you get problems because the window coordinates no longer match the 2D world coordinates. This is a common problem in graphics programming, where different coordinate systems are involved. What you need is to convert your mouse coordinates to world coordinates, and there is a function for that: window.ConvertCoords(x, y).
Laurent Gomila - SFML developer

robvleugel

  • Newbie
  • *
  • Posts: 29
    • View Profile
Window resize
« Reply #2 on: December 28, 2011, 07:49:26 pm »
Thanks for the quick answer, it works now!

The only thing that bothers me now is that I'm no longer able to use just the sf::input, I have to give classes acces to the RenderWindow in order to use ConvertCoordinates.

Thanks for the help!