Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help,
read this .
gfreak
Prole
Posts: 29 Joined: Wed Jan 04, 2012 5:32 pm
Post
by gfreak » Sat Jan 28, 2012 1:25 pm
i have an sound (1.wav)
and i want to play it every time i press "s"
easy:
Code: Select all
s = love.audio.newSource( '1.wav', 'static' )
function love.keypressed(k)
if k == "s"
love.audio.stop(s)
love.audio.play(s)
end
but i dont want the stop and i ask my self is there is a better way then:
Code: Select all
function love.keypressed(k)
if k == "s"
local s= love.audio.newSource("1.wav", "static")
love.audio.play(s)
end
i dont want to load the same data over and over again (feels stupid)
so will working with love.sound.newSoundData fix my problem?
tentus
Inner party member
Posts: 1060 Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:
Post
by tentus » Sat Jan 28, 2012 3:00 pm
The first way is the right way to do it.
gfreak
Prole
Posts: 29 Joined: Wed Jan 04, 2012 5:32 pm
Post
by gfreak » Sat Jan 28, 2012 5:03 pm
tentus wrote: The first way is the right way to do it.
if i want it yes
but i want to have multiple "1.wav"s running
i want if the engine caches it or it will be loaded multiple times and if love.sound.newSoundData is the right solution
Robin
The Omniscient
Posts: 6506 Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:
Post
by Robin » Sat Jan 28, 2012 5:09 pm
This should probably work right:
Code: Select all
function newsource()
return love.audio.newSource( '1.wav', 'static' )
end
sources = {}
function playsource()
for i, s in ipairs(sources) do
if s:isStopped() then
love.audio.play(s)
return
end
end
table.insert(sources, newsource())
love.audio.play(sources[#sources])
end
function love.keypressed(k)
if k == "s" then
playsource()
end
end
It only creates a new source if there is no stopped source available.
Taehl
Dreaming in associative arrays
Posts: 1025 Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:
Post
by Taehl » Sat Jan 28, 2012 5:32 pm
Ensayia and I created
TEsound to make things like this painless. It also makes things like playing random sounds, looping music, and volume control easier.
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+.
kikito
Inner party member
Posts: 3153 Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:
Post
by kikito » Sat Jan 28, 2012 5:47 pm
When I write def I mean function .
gfreak
Prole
Posts: 29 Joined: Wed Jan 04, 2012 5:32 pm
Post
by gfreak » Sat Jan 28, 2012 6:18 pm
kikito wrote: There is also
slam .
thanks!
but:
will multiple plays lead to multiple love.audio.newSource => more ram or even worse: more I/O by reading the same file more than once ?
nevon
Commander of the Circuloids
Posts: 938 Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:
Post
by nevon » Sat Jan 28, 2012 8:22 pm
For sounds, you should load them once as sounddata, and then use that sounddata to create a new source when you need to play it.
gfreak
Prole
Posts: 29 Joined: Wed Jan 04, 2012 5:32 pm
Post
by gfreak » Sun Jan 29, 2012 2:25 pm
nevon wrote: For sounds, you should load them once as sounddata, and then use that sounddata to create a new source when you need to play it.
thanks that what was what i want to hear
i try to patch slam for this (only for static ones of course)
vrld
Party member
Posts: 917 Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:
Post
by vrld » Mon Jan 30, 2012 11:11 am
gfreak wrote: nevon wrote: For sounds, you should load them once as sounddata, and then use that sounddata to create a new source when you need to play it.
i try to patch slam for this (only for static ones of course)
Slam already does this for you. In fact, this is kind of slam's point
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.
hump |
HC |
SUIT |
moonshine
Users browsing this forum: Ahrefs [Bot] , Bing [Bot] , Google [Bot] , Semrush [Bot] and 2 guests