SfxFader... getting it to work


(Alex K) #1

Hello. I am working on background music for my game. I noticed that Flashpunk has a class that handles fading out old songs just as a new song starts playing. This is exactly what I need. However, I have not been able to get SfxFader to work, and I have not been able to find any sample code online showing exactly how this class can be used. Has anyone had luck with it? Any code you can point me to beyond the standard API documentation for it?

Thank you.


(Ultima2876) #2

I haven’t used it firsthand (I use SeiON for audio, it’s a little more robust) but looking at the docs it appears to be a Tween. For tweens to work you need to add them to an Entity using the Entity’s addTween method; that way, they get hooked in to the update cycle. Have you tried that? :wink:


(Alex K) #3

That did the trick. Thank you. If anyone else has the same issue, the following 3 lines of code are what worked for me:

// assign it a song
var Fader:SfxFader = new SfxFader(Music_Collection[1]);

// add it to the update loop, this is what I was missing
addTween(Fader); 

// a call to switch songs
Fader.crossFade(Music_Collection[0], true, 100, 1, null); 

That’s it!