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

Author Topic: Best way to implement a basic UI?  (Read 2160 times)

0 Members and 1 Guest are viewing this topic.

Svenske

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Best way to implement a basic UI?
« 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

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Best way to implement a basic UI?
« Reply #1 on: March 24, 2019, 08:17:35 pm »
Draw them on a second sf::View that doesn't move. You don't even need them to draw them "faraway".

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Best way to implement a basic UI?
« Reply #2 on: March 24, 2019, 08:20:04 pm »
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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Re: Best way to implement a basic UI?
« Reply #3 on: March 24, 2019, 11:54:13 pm »
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.

 

anything