# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### Dark GDK / [DarkGDK 2.0] fixed healthbar question.

Message
Posted: 26th Jul 2012 22:48
how ?

i want a sprite that its X size (width) will be a miximum of 50.
and that 50 unites represent the health point of a creep.

but creeps may have 400 or 1000 health points and if a creep have
100 or 200 or 500 hp it will show on a maximum of 50 units in the health point sprite.

i need some devision code or something i just cant figure it out.
can someone help ?

ty.

[img] http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=2378306 [/img]
Posted: 27th Jul 2012 00:24
Math. Convert the current health of the creep to a percentage of the creep's maximum.

The fastest code is the code never written.
Posted: 27th Jul 2012 00:54
that works nice but its not what i asked
with the one you showed
if the creep has 50 hp , it will show a tiny bar
if it has 100 hp it will show a bit larger
300 400 500 and so on

what i wants is an algo
that will make no matter what hp to show a full value of 50 units.

so 400 is 50 units of healt bar and also 100
both visually the same size..

Posted: 27th Jul 2012 05:50
Noi it won't. The "MaxCH" is whatever the creeps maximum health is. The "CH" is the creeps current health. Converting this to a percentage is on the third line. This will give you a value of 0.0f-1.0f. When multiplied by 50, you will get a minimum bar of 0 and maximum of 50 (EVERY TIME) no matter what the "CH" and "MaxCH" is. This will give you "visually the same size" when the creep's current health is maximum. It will drop in size, slowly going to 0 as you hit it. TRUST ME.

The fastest code is the code never written.
Posted: 27th Jul 2012 10:43
my bad!! it works great !
Thank you.