Has someone ever thought about how to code a progress bar? Say, the bar should be full after 5 secs, and it should be slowly uodated.
Thanks!
Sure,
In setup:
prog = 10
rate = 2.5
In draw():
rectMode(CORNER)
rect(2, HEIGHT - 15, prog, 15)
if ElapsedTime < 5
then prog = prog + rate
elseif ElapsedTime > 5 then
prog = WIDTH - 10
end
Note: I wrote this specifically to fill in landscape mode. You would have to slow the rate so that it would work in portrait mode
If you want to run it in full screen mode, change rate to 3.5 (landscape) and leave it as 2.5 for fullscreen portrait mode
Edit: To make it support both simply add
if CurrentOrientation == 3 or CurrentOrientation == 2 then
rate = 3.5
else rate = 2.5
end
to the draw function and take rate out of setup
Slightly revamped version:
Leave setup(), but in draw():
fill(0, 174, 255, 255)
rectMode(CORNER)
rect(2, HEIGHT - 50, prog, 50)
if CurrentOrientation == 3 or CurrentOrientation == 2 then
rate = 3.55
else rate = 2.65
end
if ElapsedTime < 5
then prog = prog + rate
elseif ElapsedTime > 5 then
prog = WIDTH - 2
end
fill(127, 127, 127, 255)
w,h = textSize("LOADING...")
if prog > w then
text("LOADING...", prog - prog/2, HEIGHT - 25)
end
I had thought of making a class for one. Perhaps in the next few days.
Many thanks to you all. I completely forgot about ElapsedTime command … Maybe a wait command would be great to have.
Yeah I will be making one with rounded corners and such soon as well. I will post if I ever get it complete.