Hi!
I've made small example for timer with countdown and GUI.
GUI, countdown with progress bar
GUI, countdown with progress bar
- Attachments
-
- countdown-timer-06.love
- (1.5 KiB) Downloaded 246 times
Re: GUI, countdown with progress bar
Nice design
I found it a bit confusing that the "10" timer starts at "9" and stops after "0". This happens because you round down. If you round half away from from zero (commercial rounding) then the timer feels better:
And I would extract a function to create "lines". This removes a lot of duplicated code and makes love.load() much smaller:
I was especially surprised by your empty love.update() function. But after I found your calculations with love.timer it was pretty easy to understand how you "update" the timers.
Here are the changes I talked about:
I found it a bit confusing that the "10" timer starts at "9" and stops after "0". This happens because you round down. If you round half away from from zero (commercial rounding) then the timer feels better:
Code: Select all
line.button.text = math.floor (time+0.5) .. ' s'
Code: Select all
function create_line(y, time)
return { -- line
area = get_area{x=10, y=y, h=40, sw=10},
button =
{
area=get_area{x=10, y=y, h=40, w=200, s=2},
text="timer "..time.." s",
default_text="timer "..time.." s",
progress = 0
},
result =
{
area=get_area{x=210, y=y, h=40, sw=10, s=2},
text=0,
},
start = 0,
enabled = false,
timer = time -- seconds
}
end
Here are the changes I talked about:
Re: GUI, countdown with progress bar
Thanks Xurgo!
You are right, I have this feeling too: the 0 seconds is shown really too long. After multiple showing was ok, but at start I was some confused.
Maybe it must be ceil(time), the same as the microwave
It wasn't in function for better understanding.
I want to use the timer such way, I hope that the timer can work if this program will be closed, like by all mobile games.
You are right, I have this feeling too: the 0 seconds is shown really too long. After multiple showing was ok, but at start I was some confused.
Maybe it must be ceil(time), the same as the microwave
It wasn't in function for better understanding.
I want to use the timer such way, I hope that the timer can work if this program will be closed, like by all mobile games.
Re: GUI, countdown with progress bar
Now it works! You can start all timers, close the program, but the progress will be continued!
Special functions:
Special functions:
Code: Select all
function load_table(name)
local chunk, errormsg = love.filesystem.load( name..'.lua' )
if not (errormsg) then
return chunk()
else
print('errormsg: '..errormsg)
end
end
Code: Select all
function savetable(tabl, name)
love.filesystem.write(name..".lua", 'return '.. serialize(tabl))
end
Code: Select all
serialize = function (tabl, indent)
indent = indent and indent .. ' ' or ' '
local str = indent..'{'
local bool = true
for i, v in pairs (tabl) do
local pr = (type(i)=="string") and i..'=' or ''
if type (v) == "table" then
str=str..string.char(10) -- new line before table
str = str..pr..serialize(v, indent)..','..string.char(10)
bool = true
elseif type (v) == "string" then
str = str..pr..'"'..tostring(v)..'"'..','
bool = false
else
str = str..pr..tostring(v)..','
bool = false
end
end
if bool then
str = str:sub(1, -3) -- remove last comma and char10
else
str = str:sub(1, -2) -- remove last comma
end
str=str..'}'
return str
end
- Attachments
-
- countdown-test-04.love
- (2.06 KiB) Downloaded 197 times
-
- countdown-test-03.love
- (2.08 KiB) Downloaded 194 times
-
- countdown-test-02.love
- (2.07 KiB) Downloaded 190 times
Re: GUI, countdown with progress bar
Why the version 04 has this issue?
- Attachments
-
- countdown-test-05.love
- (2.12 KiB) Downloaded 192 times
Re: GUI, countdown with progress bar
Updated version, with smooth timer and resizable.
- Attachments
-
- countdown-test-06.love
- (2.11 KiB) Downloaded 215 times
Re: GUI, countdown with progress bar
Why the version 06 is portrait on the PC, but landscape on the android?
Who is online
Users browsing this forum: No registered users and 4 guests