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

Author Topic: Shape deformed after resizing the window  (Read 2695 times)

0 Members and 1 Guest are viewing this topic.

jjjaime

  • Newbie
  • *
  • Posts: 10
    • View Profile
Shape deformed after resizing the window
« on: April 01, 2013, 02:55:30 pm »
I've created a very simple app that renders a square with size 200:

sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(200, 200));
rectangle.setFillColor(sf::Color::Magenta);
rectangle.setPosition(10, 10);
window.draw(rectangle);
 

The square is rendered correctly. However, when the window is resized, the square is deformed into a rectangle and the size is reduced or increased according to the size of the window. Perhaps it's my misunderstanding and size and position are related to the window size? Is that correct? How could I create a shape with a specific size (and the same in height and width)?

I'm using the SFML v2.0 available at http://www.sfml-dev.org/download.php (not the latest version in Git).

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Shape deformed after resizing the window
« Reply #1 on: April 01, 2013, 03:14:27 pm »
You have to catch the Resized event and resize the window's view accordingly.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

jjjaime

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Shape deformed after resizing the window
« Reply #2 on: April 01, 2013, 05:14:09 pm »
Thanks. It works. I've used the following code:

if (event.type == sf::Event::Resized) {
      window.setView(sf::View(sf::FloatRect(0, 0, event.size.width, event.size.height)));
}
 

I will look into the View class. However, I cannot understand why it is required. I guess that the normal situation should be that the whole window corresponds to a view unless it is modified by the developer.