SFML community forums
Help => Graphics => Topic started by: Svenske on March 24, 2019, 07:32:25 pm
-
Hi there,
I am making a game where the main sf::View follows the player as they wander through a large world. I would like to start imlementing a UI on top of this, but I am not sure the best way to do this. Should I have a second view pointing to an artibitrary faraway area where i draw my ui elements and then just show that view on top of my world view? Or should i just move my UI elements everytime my character moves? Or is there a much better way to do this?
Any help is appreciated
Thanks
-
Draw them on a second sf::View that doesn't move. You don't even need them to draw them "faraway".
-
Using a separate view is likely the best option. Using one for the 'scene' or world view and another for the UI simplifies your UI positioning as it's be generally static within that view, meaning that moving your scene view doesn't affect your UI. This is also conceptually more logical as the two visuals are kept as completely separate things.
-
Like others have said, essentially in your game loop you'll need to:
1. Set the render window's view to your "main" view.
2. Draw all the "game" stuff. The moving parts, etc.
3. Set the render window to a separate "UI" view.
4. Draw the UI stuff.
The UI's positions can be anything at all. Since you're drawing them at a completely separate time as the game entities, and because it's on a completely different view, doing stuff like moving the "main" view won't effect the UI stuff at all.