Health Bars-The Easy WayFor this tutorial, I will be using
VerticalBarBackBorder -Background Bar-Make this as high as the the maximum of you Health in the game-So if you have 80MAX HP, your sprite needs to be at least 80 pixels high
VerticalBarBorder-The Health Bar-Make this only 1 Pixel high
HorizontalBarBackBorder-Background Bar-Make this as wide as the the maximum of you Health in the game-So if you have 80MAX HP, your sprite needs to be at least 80 pixels wide
HorizontalBarBorder-The Health Bar-Make this only 1 Pixel wide
VerticalBarBack-Background Bar-Make this only 1 Pixel high
VerticalBar-The Health Bar-Make this only 1 Pixel high
HorizontalBarBack-Background Bar-Make this only 1 Pixel wide
HorizontalBar-The Health Bar-Make this only 1 Pixel wide
global.HP
global.maxHP
Hud Object (This is where you put the code IN THE DRAW EVENT!)
Horizontal BarRight let's start with the basics. This is what you do. say you want it to be at point 0,0
For the sake of the code, My sprite's height is 8 pixels but you can change it to whatever
You would put this code in.
draw_sprite_stretched(HorizontalBarBack,-1,view_xview+0,view_yview+0,global.maxHP,8)
draw_sprite_stretched(HorizontalBar,-1,view_xview+0,view_yview+0,global.HP,8)
That's easy.
Vertical BarNow let's get a vertical bar. This is what you do. say you want it to be at point 0,0
This time, My sprite's width 8 pixels but you can change it to whatever
You would put this code in.
draw_sprite_stretched(VerticalBarBack,-1,view_xview+0,view_yview+0,8,global.maxHP)
draw_sprite_stretched(VerticalBar,-1,view_xview+0,view_yview+0,8,global.HP)
That's also easy.
Horizontal Bar With BorderRight now it's going to get harder. Let's add a border. This time, you must work out what the MAX HP is and add a number to the end to get your width of the background. For this, I have chosen global.maxHP to go no more than 100 and I will give it a border of 2 pixels so it will be 104 X 10 pixels. This is what you do. say you want it to be at point 0,0
For the sake of the code, My sprite's height is 8 pixels but you can change it to whatever
You would put this code in.
draw_sprite_stretched(HorizontalBarBackBorder,-1,view_xview+0,view_yview+0,104,10)
draw_sprite_stretched(HorizontalBarBorder,-1,view_xview+2,view_yview+2,global.HP,8)
That's okay.
Vertical Bar With BorderNow let's get a vertical bar. This is what you do. say you want it to be at point 0,0
This time, My sprite's width 8 pixels and my background's 10 X 104 Pixels but you can change it to whatever
You would put this code in.
draw_sprite_stretched(VerticalBarBackBorder,-1,view_xview+0,view_yview+0,10,104)
draw_sprite_stretched(VerticalBarBorder,-1,view_xview+0,view_yview+0,8,global.HP)
This is hard to understand.
And that's it. Anything in red can be changed. Changing anything else can ruin your bar. ENJOY!! I will do the rest of the highlighting later.