Page 1 of 1

[SOLVED] How can i rewind a sound source, now that love.audio.rewind(source) has been removed?

Posted: Wed Aug 15, 2018 3:29 pm
by unixfreak
Hi, tried searching, and fiddling about but cannot find a way to do this.

As per; https://love2d.org/wiki/love.audio.rewind (which is now removed since 11.0)

An example why i'd like to find a way to do this; a player can collect a series of pickups (coins, gems or whatever), which all use the same sound effect that could be an entire second long. But you may pickup/collide with many objects in a single second, and then things sound very spam-like and noisy as you have duplicate sources spamming away.

This is what i had used previously, only requiring a single source;

Code: Select all

function sound:play(fx)
	love.audio.rewind(fx)
	fx:play()
end
What i currently have as a temporary workaround (very spammy and noisy), and i believe :clone() makes many duplicates of the same source;

Code: Select all

function sound:play(fx)
	fx:clone():play()
end
How can i recreate that previous behaviour without the love.audio.rewind() function?

Re: [SOLVED] How can i rewind a sound source, now that love.audio.rewind(source) has been removed?

Posted: Wed Aug 15, 2018 3:49 pm
by unixfreak
Found a solution... turns out it was quite simple. Now it seems :stop() on an audio source automatically rewinds. Solved.

Code: Select all

function sound:play(fx)
	fx:stop()
	fx:play()
end

Re: [SOLVED] How can i rewind a sound source, now that love.audio.rewind(source) has been removed?

Posted: Wed Aug 15, 2018 4:52 pm
by zorg
There's a simpler solution

Code: Select all

sound:seek(0)
This is functionally equivalent to the old source:rewind function, and it continues playing without you needing to call play, if it was playing already.