I was wondering if anyone could provide me with the logic for creating a sort of display bar, which decreases as player health decreases.
I came up with this so far… but the bar sort of collapses in on itself, as opposed to declining from right to left…
[code]
local backBar = display.newRoundedRect(0, 0, 150, 50, 12)
backBar.strokeWidth = 3
backBar:setFillColor(250, 0, 0)
backBar:setStrokeColor(0, 0, 180)
backBar.x = 200
backBar.y = 200
local fuelBar = display.newRoundedRect(0, 0, 150, 50, 12)
fuelBar.strokeWidth = 3
fuelBar:setFillColor(0, 250, 0)
fuelBar:setStrokeColor(0, 0, 180)
fuelBar.x = 200
fuelBar.y = 200
fuelBar.xScale = 1
function move() --Moves player and players “fuel” gauge
player:applyLinearImpulse(0, -.05, player.x, player.y)
player.linearDampening = 50
fuelBar.xScale = fuelBar.xScale - .01
end
local function impulse( event )
local me = event.target
local phase = event.phase
if “began” == phase then
– Start Focus
me.alpha = 0.6
display.getCurrentStage():setFocus( me , event.id )
me.isFocus = true
Runtime:addEventListener( “enterFrame”, move)
elseif me.isFocus then
if “ended” == phase or “cancelled” == phase then
– End Focus
display.getCurrentStage():setFocus( me , nil )
me.isFocus = false
me.alpha = 0.25
Runtime:removeEventListener( “enterFrame”, move )
end
end
move()
end
if expertMode == “enabled” then
physics.addBody(player, “dynamic”,{ density = .1, shape = {6, -35 , -3, 20 , -17, 22 , -9, -44 }})
player.isFixedRotation = true
local button = display.newImage(“nextlevelbtn.png”)
button.x = 100
button.y = 100
button.alpha = 1
button:addEventListener( “touch”, impulse )
hudGroup:insert(button)
end
[import]uid: 28912 topic_id: 7572 reply_id: 307572[/import]