GUI, countdown with progress bar

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

GUI, countdown with progress bar

Post by darkfrei »

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 1922 times
countdown-timer-06.love
(1.5 KiB) Downloaded 62 times
Xugro
Citizen
Posts: 90
Joined: Wed Sep 29, 2010 8:14 pm

Re: GUI, countdown with progress bar

Post by Xugro »

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 42 times
User avatar
darkfrei
Party member
Posts: 174
Joined: Sat Feb 08, 2020 11:09 pm

Re: GUI, countdown with progress bar

Post by darkfrei »

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: 174
Joined: Sat Feb 08, 2020 11:09 pm

Re: GUI, countdown with progress bar

Post by darkfrei »

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 42 times
countdown-test-03.love
(2.08 KiB) Downloaded 42 times
countdown-test-02.love
(2.07 KiB) Downloaded 41 times
User avatar
darkfrei
Party member
Posts: 174
Joined: Sat Feb 08, 2020 11:09 pm

Re: GUI, countdown with progress bar

Post by darkfrei »

Why the version 04 has this issue?
Attachments
countdown-test-05.love
(2.12 KiB) Downloaded 43 times
Screenshot_20210222-222429.jpg
Screenshot_20210222-222429.jpg (157.2 KiB) Viewed 1711 times
User avatar
darkfrei
Party member
Posts: 174
Joined: Sat Feb 08, 2020 11:09 pm

Re: GUI, countdown with progress bar

Post by darkfrei »

Updated version, with smooth timer and resizable.
Attachments
2021-02-27T11_42_53-Untitled.png
2021-02-27T11_42_53-Untitled.png (18.57 KiB) Viewed 1590 times
countdown-test-06.love
(2.11 KiB) Downloaded 44 times
User avatar
darkfrei
Party member
Posts: 174
Joined: Sat Feb 08, 2020 11:09 pm

Re: GUI, countdown with progress bar

Post by darkfrei »

Why the version 06 is portrait on the PC, but landscape on the android?
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests