How to make a bar moving up and down? (Beginner question)

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]

Moving the meter in an enterFrame listener is easy. Moving it fast with a fine grain is the hard part.

Can Corona display an iteration between 0 and 100 in 1-point increments within the span of one second (or less!)? Given that we are reduced to 30/60FPS, I would say at this point it is impossible. That means fine grain controls (such as a power meter from 0% to 100%) will be slooooow… at most, we can increase to 60 every 1 second. For the game I’m considering, that’s unacceptable.

Here’s the challenge: display on the screen the integers 1 to 100 inclusive in less than a second. Can it be done with Corona SDK? It’s a simple question, yet nobody can seem to answer it.
[import]uid: 61132 topic_id: 10636 reply_id: 39114[/import]

I think I currently would only need it to go from 0 to 20, but I’m still interested in how you’d do that and if its possible. I’m sure a lot of people need something like this, if its not do able right now it would be best to request it, and possibly they could add it. [import]uid: 65258 topic_id: 10636 reply_id: 39165[/import]

From 0 to 20 is definitely doable. croisened’s code should get you started on a solution. You just need to change the starting, interval, and max values to what you need them to be.
[import]uid: 61132 topic_id: 10636 reply_id: 39168[/import]

If you want to see what code I have used to make the video above, well, you can find it on howto.oz-apps.com site at http://howto.oz-apps.com/2011/06/make-bobbing-bar.html

I can share code, but I request that you help back by following my twitter/facebook/sites.

cheers,

?:slight_smile:

twitter : @ozapps
twitter: @whatsin4me

http://reviewme.oz-apps.com
http://iphone.oz-apps.com
http://howto.oz-apps.com
Facebook : http://www.facebook.com/pages/ReviewMe/137640632964588 [import]uid: 3826 topic_id: 10636 reply_id: 39191[/import]

Thanks, I really appreciate your help. Gonna check out your twitter. [import]uid: 65258 topic_id: 10636 reply_id: 39306[/import]