HudPainter - Use cases?

Started by fishy 4 posts 79 views

Reply on sbox.game
  1. #1
    fishy 1,548
    Had a discussion on Discord about HudPainter and it's use cases - the documentation kind of just leaves me with more questions than answers.

    https://sbox.game/dev/doc/systems/ui/painting-a-hud/

    Each camera has a HudPainter that can be used to draw onto the HUD. You do this every frame, in any Update function. This is more efficient than Razor panels, but it is not interactive. 

    What exactly is the use case for this?

    When it says more efficient, is that in terms of performance? Or more efficient in the time/effort it takes to do, whatever HudPainter is designed to do? 

    Why would/should HudPainter be used instead of a screen panel + Razor component combo? What can we do with this that we couldn't or shouldn't do in Razor?
  2. #2
    matt Facepunch 2,045
    If you are making a crosshair it's simpler and quicker in terms of code and performance to draw 4 lines instead of clumsily laying out 4 panels in UI

    You wouldn't make a game on the web out of divs and css
  3. #3
    fishy Started this 1,548
    Okay thanks, by the sounds of it, it's a pretty limited/unique use case for things like crosshairs then. 
  4. #4
    garry Facepunch 2,270
    Under the good the HudPainter is a CommandList, so it's a real clean, easy way to draw to the HUD. It's simple stuff at the minute but our intention is to expand it over time, so it's really powerful and simple.