health bar maths

For questions about using Classic.

Post » Sun Jan 18, 2009 4:19 pm

Say i have a sprite thats however many pixels in width and i want it to reflect how much health an object has.

It has a private value, 100 being full health and 0 being dead, whats the maths to make the sprite width shrink proportionaly to the value?

thanks.
B
37
S
19
G
18
Posts: 614
Reputation: 10,233

Post » Sun Jan 18, 2009 4:38 pm

um, if your image point is at the most left or right of the sprite you can just do set width to ('health'), and itll work fine

or if you want it to be a give length you can do (('health')/100)*(put whatever the maximum of your bar length is here)
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Sun Jan 18, 2009 4:51 pm

Thanks.
B
37
S
19
G
18
Posts: 614
Reputation: 10,233

Post » Sun Jan 18, 2009 4:57 pm

Just a note, you may wish to use a tiled background instead of a Sprite for a healthbar, if you want anything other than a solid colour.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Sun Jan 18, 2009 5:53 pm

Is that so the image doesnt get distorted?

Not sure if i can use the tiled background object because it doesnt allow private values, which i need.
B
37
S
19
G
18
Posts: 614
Reputation: 10,233

Post » Sun Jan 18, 2009 6:04 pm

I've added them for the next build, but yes, that's why you'd use it :).
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest