ForumsProgramming ForumHealth bars problem

5 2557
staticzone
offline
staticzone
67 posts
Nomad

How do make the health bar always be 100 width no madder how much health you program your character to have?

here is the code on the char_hp

onClipEvent(enterFrame)
{
this._xscale=_root.char_hp;
if(_root.char_hp<=0)
_root.char_hp=0;
}


here is the code on the frame

stop();
char_hp=100;
energy_bar=400;

Thanks

  • 5 Replies
PixelSmash
offline
PixelSmash
566 posts
Nomad

hmm... shouldn't be too hard, really. Now that I think about it, it's probably fixed by adding a char_hp_max value... like this:

stop();
char_hp_max=200;
char_hp=100;
energy_bar=400;

onClipEvent(enterFrame)
{
this._xscale=(_root.char_hp/_root.char_max_hp)*100;
if(_root.char_hp<=0)
_root.char_hp=0;
}

You see, you can set the hp to nearly infinite, but if you don't specify the maximum hp, there's no real way to make sure it doesn't go beyond 100. After all, flash does know how much hp you have, but doesn't know what percentage that is of the total health. In the example above, your health bar will start at 50%, which equals 50 pixels wide.

Give it a shot, and let me know! Good luck!

staticzone
offline
staticzone
67 posts
Nomad

hmm didnt work...

PixelSmash
offline
PixelSmash
566 posts
Nomad

Hmm, did it give any errors? What exactly happened / didn't work?

rino
offline
rino
27 posts
Nomad

all that happened it that the character faced the other direction

staticzone
offline
staticzone
67 posts
Nomad

@PixelSmash

Its weird it just didn't work
But it gave no errors

But the health is till exceeding 100 width, hmm

Showing 1-5 of 5