android - Corona SDK - Create Health Bar with different HP value -
i have rectangle image use health bar fill. health goes down, width of bar decreases until 0. part of code works fine, bar's width goes down , stays in same x position width being changed.
my problem when create monster different hp value, different width of health bar. how can create same size rectangle different hp value? thank much.
-- create health bar monsterbar = display.newrect( 20, 160, 26, 10 ) monsterbar:setreferencepoint(display.bottomleftreferencepoint) monsterbar:setfillcolor( 80,150, 0 ) -- monster hit monsterbar.width = monsterbar.width - scorehud.text monsterbar:setreferencepoint(display.bottomleftreferencepoint)
you need use percentile intermediate value, can use in progress bar.
for example, compute monster health percent that, making sure hp current <= hp max:
local nmonsterhppercentile = (nmonsterhpcurrent / nmonsterhpmax) * 100
once have percentile value, adapt rectangle created max size of "100" example (or 200, 300 etc need multiply monster percentile) , display individual rectangles according calculated percentile... example, if got 62% nmonsterhppercentile, , rectangle has width 100, loop adds individual hp rectangle bar each 10%.
Comments
Post a Comment