SFML community forums

Help => Window => Topic started by: hdsiria on August 31, 2023, 05:40:15 am

Title: When using sf::View, the content displayed in the window will change as the pers
Post by: hdsiria on August 31, 2023, 05:40:15 am
When using sf::View, the content displayed in the window will change as the perspective moves,How to keep a graphic in a specific position in the window at all times
My current approach is to follow the perspective and change the position of the content, so as to always maintain a specific position in the window. Is there a better way?For example, simply skip the view and draw on the window
Title: Re: When using sf::View, the content displayed in the window will change as the pers
Post by: eXpl0it3r on August 31, 2023, 11:43:22 am
If you want for example an UI element always shown at the same location, it's better and easier to just use a separate view for those elements.

See the view tutorial: https://www.sfml-dev.org/tutorials/2.6/graphics-view.php#defining-how-the-view-is-viewed
Title: Re: When using sf::View, the content displayed in the window will change as the pers
Post by: Hapax on August 31, 2023, 12:24:59 pm
As a simple example to what eXpl0it3r mentioned:
sf::View mainView; // the view you are using now. you can move this however you like
sf::View windowView; // this one matches the window
windowView = window.getDefaultView(); // this is how you can match the view to the window (but it will need updating if the window changes)
// ..
window.setView(mainView); // your normal view
window.draw(yourStuff); // the stuff that moves "perspective"
window.setView(windowView); // static window view
window.draw(ui); // the stuff you want to draw relative to the window, ignoring the other view such as a user interface

Remember, though, that - depending on how you use it - you may need to set the window to a specific view before doing certain updates. This is if you use the "current window's view" for any calculations; you can, of course, remove this requirement and use the correct view directly.