Nope, “fadeOut()” won’t automatically remove/unload the sound. It will free up the channel when it completes, but that doesn’t remove the sound file from memory.
Since your sound will “overlap” into a new scene, you’ll have to build some kind of removal function in your project core, outside of the Storyboard scenes. The “fadeOut()” API features an “onComplete” call which you can use for this.
In general, I suggest you build some kind of sound management table in your project core, independent of the scenes. It will just be safer, defensive programming. Then you can add/remove/dispose of sounds in that table, so there won’t be memory leaks from sounds called/played individually from scenes that are being swapped around.
Did you ever solve this? I actually informed you incorrectly: the “onComplete” callback is available from the audio.play() API, not from the audio.fadeOut() API. So, I think you’ll need to play the sound as normal, do a fadeOut (separately), then put the onComplete argument in the play call, like this:
[lua]
local sparkleSound = audio.loadSound( “sparkle.wav” )
local function disposeSound( event )
audio.stop( event.channel )
audio.dispose( event.handle )
sparkleSound = nil
end
local sound = audio.play( sparkleSound, { onComplete=disposeSound } )
audio.fadeOut( { channel=sound, time=1000 } )
[/lua]
Notice that in the fadeOut() call, “channel=sound” is used because “sound” (the local variable set to play the sound) is equal to the channel it plays on… you need that because fadeOut() requires the channel to fade, but you might not know which channel it’s on unless you specify a channel… and since you probably don’t want to do that, “sound” gives you the channel to use with fadeOut().
Nope, “fadeOut()” won’t automatically remove/unload the sound. It will free up the channel when it completes, but that doesn’t remove the sound file from memory.
Since your sound will “overlap” into a new scene, you’ll have to build some kind of removal function in your project core, outside of the Storyboard scenes. The “fadeOut()” API features an “onComplete” call which you can use for this.
In general, I suggest you build some kind of sound management table in your project core, independent of the scenes. It will just be safer, defensive programming. Then you can add/remove/dispose of sounds in that table, so there won’t be memory leaks from sounds called/played individually from scenes that are being swapped around.
Did you ever solve this? I actually informed you incorrectly: the “onComplete” callback is available from the audio.play() API, not from the audio.fadeOut() API. So, I think you’ll need to play the sound as normal, do a fadeOut (separately), then put the onComplete argument in the play call, like this:
[lua]
local sparkleSound = audio.loadSound( “sparkle.wav” )
local function disposeSound( event )
audio.stop( event.channel )
audio.dispose( event.handle )
sparkleSound = nil
end
local sound = audio.play( sparkleSound, { onComplete=disposeSound } )
audio.fadeOut( { channel=sound, time=1000 } )
[/lua]
Notice that in the fadeOut() call, “channel=sound” is used because “sound” (the local variable set to play the sound) is equal to the channel it plays on… you need that because fadeOut() requires the channel to fade, but you might not know which channel it’s on unless you specify a channel… and since you probably don’t want to do that, “sound” gives you the channel to use with fadeOut().
I having memory leak troubles, I was under the impression that the audio cleaned itself up from scene to scene. Must we dispose every single file we use when changing to new scene with something like director.
Audio definitely needs to be disposed of… not necessarily between scenes, but at some point it does need to be. Logically though, if you are leaving a scene and don’t need any of the audio used in that scene, you should dispose of it for memory reasons.
I having memory leak troubles, I was under the impression that the audio cleaned itself up from scene to scene. Must we dispose every single file we use when changing to new scene with something like director.
Audio definitely needs to be disposed of… not necessarily between scenes, but at some point it does need to be. Logically though, if you are leaving a scene and don’t need any of the audio used in that scene, you should dispose of it for memory reasons.