Godot Version
4.5.1
Question
I am now in the part where I am building my HUD for the tower defense game that I am making and before I had a closed off menu but now I wanted to open it up so the game didn't feel closed off. This is how it looks like so far which works nicely.
I was trying to change it up to look something like this
But when testing and playing around with some of the numbers I noticed that the panel elements would resize depending on the size of an element. For example the Labels which should hold a lot of higher values depending how far the player has progressed would resize and overflow from the hboxcontainer.
In my previous one my values could go up to 20 million which I think would be enough and I don’t know if anyone would reach those numbers but it would still overflow after that so I was wondering if anyone has a good solution to this issue as well as which of these two HUD’s would be better to go with.
I don’t see the text going out of the box, was that the problem?
there are many solutions to make the number smaller.
you can format the text so that it displays differently when reaching a certain number.
for example, you can check if after dividing the number the value is higher than 1:
if the number is 500, 500/1000 is 0.5, which is lower than 1.0.
but if the number is 2000, 2000/1000 is 2.0. in this case, we can keep the result and then add a K after.
we can repeat this after every if with higher numbers, like 1000000, etc, and add other symbols, like M, G, etc.
if number / 1000.0 < 1.0:
label.text = str(number)
else:
if number / 1000000 < 1.0:
label.text = str(floor(number/1000)) + "K"
else:
label.text = str(floor(number/1000000)) + "M"
well on the pictures it doesn’t but only until the 99,999 mark but after that it would cover the icon that I have and with higher numbers it would go out of the box.
But I like the solution for sure that’s a great way to cover up the higher numbers without them going out of bounds. I really didn’t think of that, Thank You!