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

Author Topic: How to fix the background in the app when scaling the window, sfml  (Read 2445 times)

0 Members and 1 Guest are viewing this topic.

vadimiz12rus

  • Newbie
  • *
  • Posts: 2
    • View Profile
Help with sfml, it is necessary to make so that the background application when scaling is not changed,

int main()
{
    ....
    View view;
    view.reset(FloatRect(0, 0, 1200, 700));
    float zoom = 1.0f;

    while (window.isOpen())
    {  
        ProcessEvents(window, clickState, zoom, view);
        ...
        window.setView(view);
        window.draw(bg);
        window.draw(vecBody.at(0).sprite);
        window.draw(text);  
    }
}
Without zoom

With zoom

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How to fix the background in the app when scaling the window, sfml
« Reply #1 on: August 16, 2016, 04:53:35 pm »
As the view size increases (zooming out does this), the co-ordinate range shown on the window increase (in that view).

To lock your image to the size of the window, you can:
  • stretch your image to match the new view size, or
  • use a separate view for the image that matches the window size.

Maybe something like:

(1)
const sf::Vector2f scale(vecBody.at(0).sprite.getTexture().getSize().x / view.getSize().x, vecBody.at(0).sprite.getTexture().getSize().y / view.getSize().y);
vecBody.at(0).sprite.setScale(scale, scale);

or

(2)
window.setView(sf::View(sf::Vector2f(0, 0), sf::Vector2f(window.getSize())));
window.draw(vecBody.at(0).sprite);

EDIT: removed the sf::View object in (2) and constructed a temporary one inside the setView call.
« Last Edit: August 16, 2016, 09:52:01 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

vadimiz12rus

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How to fix the background in the app when scaling the window, sfml
« Reply #2 on: August 16, 2016, 07:35:09 pm »
Thanks huge, all turned out.