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

Author Topic: Best way to display sprites  (Read 1309 times)

0 Members and 1 Guest are viewing this topic.

rcplusplus

  • Newbie
  • *
  • Posts: 15
    • View Profile
Best way to display sprites
« on: June 18, 2012, 03:38:52 am »
I have a window on which I'm going to display a ton of sprites for a game. I'm using SFML 2.0 which adds a view to windows automatically, which is good I hear because it converts measurements and locations for the window so it behaves the same, regardless of size. Problem is, when I resize the window, it stretches/shrinks all the sprites. Is there a way to resize the window but NOT the view? And what is the best way to set up views/windows to adjust to ALL resolutions? Because I want the game to look more or less the same on ALL screen sizes... thanks.
« Last Edit: June 18, 2012, 03:41:12 am by rcplusplus »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Best way to display sprites
« Reply #1 on: June 18, 2012, 08:28:14 am »
Quote
Is there a way to resize the window but NOT the view?
In fact you want to resize the view so that it has the same size as the window (the default behaviour is to keep the initial size -- that's why things are stretched).

You just have to catch the Resized event and reset the view with the new window size.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: Best way to display sprites
« Reply #2 on: June 18, 2012, 11:56:15 am »
I use for example this code:

else if(event.type == sf::Event::Resized)
{
        sf::Vector2f size = static_cast<sf::Vector2f>(window.getSize());

        // Minimum size
        if(size.x < 800)
                size.x = 800;
        if(size.y < 600)
                size.y = 600;

        window.setSize(static_cast<sf::Vector2u>(size));
        window.setView(sf::View(sf::FloatRect(0.f, 0.f, size.x, size.y)));
}
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/