SFML community forums

Help => Window => Topic started by: vadimiz12rus on August 16, 2016, 01:25:50 pm

Title: How to fix the background in the app when scaling the window, sfml
Post by: vadimiz12rus on August 16, 2016, 01:25:50 pm
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
(http://i.stack.imgur.com/rpJCi.jpg)
With zoom
(http://i.stack.imgur.com/O36RG.png)
Title: Re: How to fix the background in the app when scaling the window, sfml
Post by: Hapax 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:

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.
Title: Re: How to fix the background in the app when scaling the window, sfml
Post by: vadimiz12rus on August 16, 2016, 07:35:09 pm
Thanks huge, all turned out.