Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    How do I make an hud

    Help
    3
    3
    355
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      AlexTheNewCoder last edited by

      Basically I'm trying to make a hud for my game but the problem is I don't know how if anybody knows how to make huds like, health etc?

      1 Reply Last reply Reply Quote 1
      • vinicity
        vinicity F last edited by

        There are many ways to do this. It all depends on what you are after. The easiest way would be to just do a text based HUD using print(), or you could use something from the asset library... Maybe draw shapes using the shapes commands or designing some sprites in the editor.

        Maybe you want some segmented bars in the HUD? Then you can take a look at this project here:
        https://fuzearena.com/catalogs/view/5000

        Also, be mindful of the draw order: you usually want to draw your HUD last so it comes out on top of other objects. This goes especially for 3D games, since you cannot easily draw 3D objects on top of a 2D HUD, the latter will not be seen at all...

        1 Reply Last reply Reply Quote 2
        • Dave
          Dave Fuze Team last edited by Dave

          Here's a function you could copy into a project and use to draw a customisable health/stamina/mana bar! I did something similar in a game "Subs 2" @SteveZX81 and I worked on. It even has an easy colour changing effect as the bar changes size, which is really easy to customise too!

          function drawBar(x, y, width, height, value, maxValue, colourEmpty, colourFull)
              w = width/maxValue * value
              t = w/width
              col = interpolate(ease_in_out, colourEmpty, colourFull, t)
              box(x, y, w, height, col, false)
          return void
          

          With this in your program somewhere (make sure it's outside your main loop, this is a function definition and must be outside other loops/function definitions), you can simply call it and draw a hud bar anywhere on screen. We just need to pass it the values we want to use. For example, here it is in a simple program:

          // Some health variables to use for the length of the bar
          maxHealth = 20
          health = maxHealth
          
          loop
              clear()
              
              // Call our function, draw a bar at screen location (100, 100), with a maximum width of 300 pixels, height of 50 pixels:
              drawBar(100, 100, 300, 50, health, maxHealth, red, lime)
          
              // Decrease the health variable to show the bar reducing and changing coour
              health -= 0.1
              // Limit the variable so it stops at 0
              health = max(health, 0)
          
              update()
          repeat
          

          You could call that function with any set of variables, doesn't have to be health! If you had maxStamina and stamina variables, they would also work and you could use different colours, for example:

          // Draw a bar at screen location (50, 50) with max width of 250 pixels, height of 50 pixels colour shifting from yellow to gold (very subtle, looks quite nice!)
          drawBar(50, 50, 250, 50, stamina, maxStamina, gold, yellow)
          

          I hope these examples help you out!

          1 Reply Last reply Reply Quote 3
          • First post
            Last post