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)
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.