1
Graphics / Re: Sprite is drawn in incorrect position after RenderWindow is resized
« Last post by CardsChris on May 22, 2024, 10:59:57 pm »After a bit of experimenting, that solution partially worked. I figured it out so I'm going to mark the thread as solved, but for anyone who runs into this issue:
Resetting the window view is NOT enough to solve this on its own. The flow of code should be something like this:
Resetting the window view is NOT enough to solve this on its own. The flow of code should be something like this:
if (event.type == sf::Event::Resized) {
window.setView(sf::View(sf::Vector2f(window.getSize().x/2.f,window.getSize().y/2.f), sf::Vector2f(window.getSize().x, window.getSize().y)));
for (auto& i : sprites) {
i.setPosition(/*new position */);
}
}
You must adjust every drawn object/sprite's position after you change the sf::View, otherwise each drawn object is stuck with an arbitrary sf::View based on the time it was drawn before/after the resizing of the window.window.setView(sf::View(sf::Vector2f(window.getSize().x/2.f,window.getSize().y/2.f), sf::Vector2f(window.getSize().x, window.getSize().y)));
for (auto& i : sprites) {
i.setPosition(/*new position */);
}
}