Health Bar Problem

I have a rectangle image I use for a Health Bar fill. As your health goes down, the width of the bar decreases until you get to 0. For this part of the code everything works fine, the bar’s width goes down and it stays in the same x position as its width is being changed.

My problem is when I create monster with different HP value, I will get different width of the Health Bar. How can i create the same size rectangle with different HP value ?

Thank you so much~

 

-- Create Health Bar MonsterBar = display.newRect( 20, 160, 26, 10 ) MonsterBar:setReferencePoint(display.BottomLeftReferencePoint) MonsterBar:setFillColor( 80,150, 0 ) -- Monster health MonsterBar.width = MonsterBar.width - scoreHUD.text MonsterBar:setReferencePoint(display.BottomLeftReferencePoint)