GUI, countdown with progress bar

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
darkfrei
Party member
Posts: 102
Joined: Sat Feb 08, 2020 11:09 pm

GUI, countdown with progress bar

Post by darkfrei » Fri Feb 19, 2021 9:34 pm

Hi!

I've made small example for timer with countdown and GUI.
Attachments
2021-02-19T22_30_58-Untitled.png
2021-02-19T22_30_58-Untitled.png (21.12 KiB) Viewed 299 times
countdown-timer-06.love
(1.5 KiB) Downloaded 5 times

Xugro
Citizen
Posts: 88
Joined: Wed Sep 29, 2010 8:14 pm

Re: GUI, countdown with progress bar

Post by Xugro » Fri Feb 19, 2021 10:54 pm

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:

Code: Select all

line.button.text = math.floor (time+0.5) .. ' s'
And I would extract a function to create "lines". This removes a lot of duplicated code and makes love.load() much smaller:

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
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:
countdown-timer-xugro.love
(1.48 KiB) Downloaded 2 times

User avatar
darkfrei
Party member
Posts: 102
Joined: Sat Feb 08, 2020 11:09 pm

Re: GUI, countdown with progress bar

Post by darkfrei » Sat Feb 20, 2021 10:18 am

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.

User avatar
darkfrei
Party member
Posts: 102
Joined: Sat Feb 08, 2020 11:09 pm

Re: GUI, countdown with progress bar

Post by darkfrei » Sun Feb 21, 2021 6:08 pm

Now it works! You can start all timers, close the program, but the progress will be continued!

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 3 times
countdown-test-03.love
(2.08 KiB) Downloaded 3 times
countdown-test-02.love
(2.07 KiB) Downloaded 2 times

User avatar
darkfrei
Party member
Posts: 102
Joined: Sat Feb 08, 2020 11:09 pm

Re: GUI, countdown with progress bar

Post by darkfrei » Mon Feb 22, 2021 9:26 pm

Why the version 04 has this issue?
Attachments
countdown-test-05.love
(2.12 KiB) Downloaded 4 times
Screenshot_20210222-222429.jpg
Screenshot_20210222-222429.jpg (157.2 KiB) Viewed 88 times

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests