well as I stated above, my intent was to give some ideas on the art of moving the meter, certainly it is not optimized for your use. It’s what I could do in 20 minutes LOL, at any rate yeah you are going to need to address all sorts of things if you are processing in the game loop (30 or 60 fps)
One way would be to add some timers and keep track of the intervals in which you want to act, to address your issue of the number of steps I made these changes below. Now all your steps and such will be the same just adjust the delay, etc accordingly for your targetted framerate. This will be my last post on this topic, I don’t even need a power bar LOL Hope any of this helps, keep discovering… Use this and follow the instructions from my above post (IE still need the ui.lua and a play.png for it to work)
[code]
local ui = require(“ui”)
local gameT = system.getTimer()
local meterT = system.getTimer()
local elapsedT
local meterDelay = 20
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)
elapsedT = event.time - meterT
if elapsedT > meterDelay then
–Move the meter
meterT = event.time
meter.x = meter.x + meterInterval
meterInMotion = true
end
elapedT = event.time - gameT
–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: 39108[/import]
