healthBar
Posted:
Fri Dec 23, 2011 5:00 am
by raminkhan
how can I make a auto filler health bar. I mean when I hit my character, the health decreases but when i don't hit him I want his health to increase automatically how?
Re: healthBar
Posted:
Fri Dec 23, 2011 5:32 am
by Hblade
In draw actor of the player, have this somewhere
Make a variable called "timer" and do this
- Code: Select all
timer++;
if(timer>=30 && HP<50) // 1 second, 50 is max HP limit
{
HP++;
timer=0;
}
Every 1 second HP will go up by 1.
Re: healthBar
Posted:
Fri Dec 23, 2011 1:03 pm
by phyzix5761
Great simple code Hblade. Raminkhan, just make sure your game speed is 30 frames per second in order for the health to regenerate 1 point per second.
Re: healthBar
Posted:
Fri Dec 23, 2011 1:33 pm
by lcl
Hblade, better to use real_fps instead of 30.
So the code would be:
- Code: Select all
timer++;
if(timer>=real_fps && HP<50) // 1 second, 50 is max HP limit
{
HP++;
timer=0;
}
Re: healthBar
Posted:
Sat Dec 24, 2011 6:29 am
by raminkhan
but I dont get it, timer++ why do i need to make this variable? what is this variable? and how would this code load my individual health pieces which makes up a full health bar?
lcl wrote:Hblade, better to use real_fps instead of 30.
So the code would be:
- Code: Select all
timer++;
if(timer>=real_fps && HP<50) // 1 second, 50 is max HP limit
{
HP++;
timer=0;
}
Re: healthBar
Posted:
Sat Dec 24, 2011 8:29 am
by skydereign
The timer variable is what makes sure this increasing of hp only occurs once a second. All the variable does is increase to some value, and then increase hp, while setting it back to zero. If you look at the if statement, that's all it does (because it is in draw, it just repeats over and over). Now, how are you displaying hp? It sounds like you are using individual actors, in which case I'd suggest you not. It gets more complex if you do that, while the idea behind using an animation is much easier.