Page 2 of 2
Re: Circle music
Posted: Mon Nov 28, 2011 5:54 pm
by aviktorov
Ellohir wrote:Very cool; if only it sounded every time the circles touch and not one in four or five...
Seems like the more circles I draw the more touches it doesn't sound
Actually, my first version creates a lot of sources and as a result I got a memory leak. So I decided to 'pre-create' all different sources and use them. But it looks like I can't reuse them.
Re: Circle music
Posted: Mon Nov 28, 2011 6:50 pm
by Robin
A source is a single source of sound, so it can't be playing twice at the same time, probably causing these problems. What you could do is keep a list of sources, and when you need to play that sound, first check in the list if there is an unused one already:
Code: Select all
function play_source(source_list, file_name)
for i, s in ipairs(source_list)
if s:isStopped() then
s:play()
return
end
end
local s = love.audio.newSource(file_name)
source_list[#source_list + 1] = s
s:play()
end
Warning: untested, yadda yadda yadda
Re: Circle music
Posted: Mon Nov 28, 2011 11:35 pm
by Taehl
Or let
TEsound do that for you.
Re: Circle music
Posted: Tue Nov 29, 2011 7:50 pm
by aviktorov
Hey, thanks for helping me!
Here is the new version (now I store a list of sources for each unique sound).
Re: Circle music
Posted: Wed Nov 30, 2011 8:26 am
by Robin
Much better! Only sometimes there is no sound still. Also, circles inside other circles are invisible.