I have a rectangle image I use for a Health Bar fill, it sits inside my Health Bar image and needs to stay in place. 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 try to add health back to my player, I need the width to go back up (increase). When this happens, the x position of the rect is getting moved around and is not in the correct spot.
The following is my code for creating the fill rect and the Bar image, also the code that works fine for decreasing the width/hp and the code that is messing up for increasing the width/hp.
[code]
– Creating the rect and the Health Bar image –
local HpSize = display.newRect(0, 0, 70, 15, 12)
HpSize:setFillColor(155, 0, 0)
HpSize:setReferencePoint(display.TopLeftReferencePoint)
HpSize.x = 133
HpSize.y = 8
guiGroup:insert(HpSize)
local HpBar = display.newImage( “HpBar.png”, true )
HpSize:setReferencePoint(display.TopLeftReferencePoint)
HpBar.x = 160
HpBar.y = 15
guiGroup:insert(HpBar)
– This is called when the player loses health –
transition.to(HpSize, { time=100, x = 130, width=HpSize.width-4.5 } )
HpSize:setReferencePoint(display.TopLeftReferencePoint)
HpSize.x = 130
– This is called when the player gains back health –
transition.to(HpSize, { time=100, x = 130, width=HpSize.width+17.5 } )
HpSize:setReferencePoint(display.TopLeftReferencePoint)
HpSize.x = 130
[/code] [import]uid: 69700 topic_id: 17084 reply_id: 317084[/import]
[import]uid: 3826 topic_id: 17084 reply_id: 64175[/import]