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

Author Topic: When using sf::View, the content displayed in the window will change as the pers  (Read 1939 times)

0 Members and 2 Guests are viewing this topic.

hdsiria

  • Newbie
  • *
  • Posts: 23
    • View Profile
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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything