Guys try this… I threw this together and maybe it will help get going. it is certainly not optimized or anything. Some features that would be good to add would be to set up some interval timers to make the bar move faster and faster as it gets going, also if you click right when the meter hits maximum it will reset to the beginning so that needs cleaned up. Other than that maybe it will help, check it out…
You need to get a copy of the “ui.lua” file and include it in your project directory, then put this into your main.lua file and throw some small image named “play.png” in there as well to server as the trigger button.
It works like this: Click it once - the meter starts moving, click it a second time - the meter stops and a third time - it will reset to start all over again.
Enjoy…
[code]
local ui = require(“ui”)
local startingX = 10
local startingY = 100
local maxX = 310
local meterInterval = 5
local bar = display.newRect(10, 111, 300, 4) --paint a line that the meter indicator will travel on
bar:setFillColor(255,255,255,255) --set the color to white
local meter = display.newRect( startingX, startingY, 10, 25 ) --paint meter indicator
meter:setFillColor( 125, 220, 125, 255 ) --set the color to green
local readyToFire = true --track when we are ready to move the meter
local meterInMotion = false --track when the meter is in motion
local function Move(event)
–Move the meter
meter.x = meter.x + meterInterval
meterInMotion = true
–If we hit the max stop the meter
if (meter.x >= maxX) then
Runtime:removeEventListener( “enterFrame”, Move )
meter.x = maxX
print(“Meter Stopping”)
meterText.text = "Power: " … (meter.x - startingX)
meterInMotion = false
end
end
local function startMoving()
if (readyToFire) then
print(“Starting to move the meter”)
readyToFire = false
Runtime:addEventListener( “enterFrame”, Move )
else
if (meterInMotion) then
print(“Just need to stop the meter”)
Runtime:removeEventListener( “enterFrame”, Move )
meterInMotion = false
else
–reset back to the beginning
print(“Resetting the meter”)
meter.x = startingX
readyToFire = true
end
meterText.text = "Power: " … (meter.x - startingX)
end
end
local theButton = ui.newButton{
default = “play.png”,
over = “play.png”,
onRelease = function(event) startMoving() end
}
theButton.x = display.contentWidth / 2
theButton.y = 400
meterText = display.newText( “”, 10, 300, “Helvetica-Bold”, 20 )
meterText.x = display.contentWidth / 2
meterText:setTextColor( 255, 255, 255, 255 ) --> white
[/code] [import]uid: 48203 topic_id: 10636 reply_id: 38902[/import]