N
Noam Shafir
Guest
So I have been trying to program a League of Legends like health bar.
If you don't know what it means, in the League of Legends health bar, other than the regular colored health bar, every few health points there is a line, so that you can quickly determine if a player has a lot of health or little health by the amount of lines and by their space from one another.
I tried to program this sort of health bar in GameMaker by writing this in the draw event:
I will try to explain what I tried to do in the second part of the code.
First of all, I define the number of times the loop need to repeat by the number of lines I need to draw: max_hp/25.
than I draw a lines, starting from the starting point of the health bar (x-sprite_width/2-20), and going up every repeat (i*(40/(max_hp/25)), (I*(the_size_of_the_bar/the_number_of_lines)).
The Y position is working correctly, but the X position of the lines is not.
Here is a gif of the health bar, with the max health increasing by 10 each time.
(I changed the color of the health bar in the gif to orange because my recorder thought the green was a green screen.)
Thank you to anyone who helps.
If you don't know what it means, in the League of Legends health bar, other than the regular colored health bar, every few health points there is a line, so that you can quickly determine if a player has a lot of health or little health by the amount of lines and by their space from one another.
I tried to program this sort of health bar in GameMaker by writing this in the draw event:
Code:
/max_hp = 100;
// The sprite origin point is the center.
// Draw the health bar
draw_healthbar(x-sprite_width/2-20, y-sprite_height/2-40, x+sprite_width/2+20, y-sprite_height/2-20, hp*(100/hp), c_black, c_red, c_lime, 0, true, true);
// Draw the health bar lines
// I want to draw a line every 25 health points.
for (var i = 0; i < max_hp/25; i++) {
draw_line_colour(x-sprite_width/2-20+i*(40/(max_hp/25)), y-sprite_height/2-41, x-sprite_width/2-20+i*(40/(max_hp/25)), y-sprite_height/2-20, c_white, c_white);
}
First of all, I define the number of times the loop need to repeat by the number of lines I need to draw: max_hp/25.
than I draw a lines, starting from the starting point of the health bar (x-sprite_width/2-20), and going up every repeat (i*(40/(max_hp/25)), (I*(the_size_of_the_bar/the_number_of_lines)).
The Y position is working correctly, but the X position of the lines is not.
Here is a gif of the health bar, with the max health increasing by 10 each time.
(I changed the color of the health bar in the gif to orange because my recorder thought the green was a green screen.)
Thank you to anyone who helps.
Last edited by a moderator: