Hello fellow scripters, I’m working on health system which is displayed using hearts. One part of the script calculates how many and what kind of hearts must be done, at the moment there’s 3 types.
Full Heart - 2HP.
Half Heart - 1HP (With other part grayed out, think it as of 1/2).
Empty heart - (Completely grayed out).
All of the calculations for how many of each heart type should be displayed are counted into integers.
So if max HP was 8 and current HP, it would be just 4 Full Hearts.
If it was 5 HP and max HP was 8, it would be 2 full hearts, 1 half heart, and 1 empty heart.
I’ve tried various loops on how to display them in right order using GUI.DrawTexture and so on, but I couldn’t make it work right, besides that I’ve also got very very big FPS drops. What are possible ways to do it, how would you try do it, or what other way could I try for it. It would be also great if you explained direction in which I should work so I’d get it work on 4.6 Beta GUI.
If I wrote something confusing in some part, please notify me and I will try to explain it better, English isn’t my mother language, nor I’m used to forums. Thanks in advance!
A simple for loop with GUI.DrawTexture ought to work fine (plus one more DrawTexture call if you have half a heart). Why don’t you post your code (use the “insert code” button, between the movie icon and the disk icon), and perhaps we can help you find the error.
Hearts usually show up in wrong order, in most cases half heart doesn’t even show up at all, and together with all that, FPS drops very very much, any insights on how could I try fix this?
Why don’t you just draw them separately? Make a for loop to draw the full hearts, then another for loop to draw the half hearts, and lastly a loop to draw the empty ones? Skip all your crazy conditional logic. I also don’t understand why you’re using if statements to calculate the number of hearts and why you’re doing division for the empty ones. Isn’t empty always total - (full + half)?
int full = health/2;
int half = health%2;
int empty = maxhealth-full-half;
Lots of confusing conditionals in your loop too. As Kelso said, you can draw three separate loops and just keep a counter going through all three to adjust for heart position. No need for any ifs.
I would, Add them to array after you calculate them in order… full add first, then add what is remaining, IE half heart or quarter heart of monkey for that matter.
Then just draw the array to screen.
Clear it, and rebuild it as needed.
I think you are overly complicating your issue.
life Array[max hearts]
(graphic, screen position, bool filled)
/add values to array
add all your positions in order from left to right
array[0] (graphic none, screen position x,y, bool filled false)
array[1] (graphic none, screen position x,y, bool filled false)
array[2] (graphic none, screen position x,y, bool filled false)
int pos =0; // keep track of pos
//calculate how many full hearts there are and set them
array[pos] (graphic full heart, screen position x,y, bool filled true)
pos++;
loop until no more full hearts…
then check remaining life to see what your end heart will be
if half
array[pos] (graphic half heart, screen position x,y, bool filled true)
else if quarter
array[pos] (graphic quarter heart, screen position x,y, bool filled true)
loop through all items in array, if bool filled = true then draw to screen…
use array to tell what you want to draw…
end of loop.
All good advice, and I’ll add just one more: the framerate drop is almost certainly do to the print statement. Not the drawing of the hearts. A half-dozen DrawTexture calls won’t bog your game down at all.
Alright, I guess I’ll do three separate loops, but how could I make the offset for their position using some integer, like I use i as an integer in my for loop and use make one same offset trough out all 3 loops? And thanks for all the responses by the way guys!