Circle music

Showcase your libraries, tools and other projects that help your fellow love users.
aviktorov
Prole
Posts: 3
Joined: Fri Nov 25, 2011 9:53 pm

Re: Circle music

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Circle music

Post 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
Help us help you: attach a .love.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Circle music

Post by Taehl »

Or let TEsound do that for you.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
aviktorov
Prole
Posts: 3
Joined: Fri Nov 25, 2011 9:53 pm

Re: Circle music

Post by aviktorov »

Hey, thanks for helping me! :)

Here is the new version (now I store a list of sources for each unique sound).
Attachments
circles_v1.1.love
(2.34 MiB) Downloaded 136 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Circle music

Post by Robin »

Much better! Only sometimes there is no sound still. Also, circles inside other circles are invisible.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests