Author Topic: FadeIn and FadeOut not working?? How to use those methods properly?  (Read 2963 times)

xraven13

  • Active Member
  • ***
  • Posts: 213
  • Karma: +0/-0
    • View Profile
    • GemaNeko
So i make new FlxSound object :
var BckMusic:FlxSound= new FlxSound();
bckMusic.loadEmbedded(MusicClass, false);
bckMusic.fadeIn(10);

.. but i don't hear any difference when i use bckMusic.play instead fadeIn method...  Music is not fading in at all, but its playing normally....
I also tried placing bckMusic.play() after and before bckMusic.fadeIn but this doesn't give any difference either...

So what i am doing wrong :D
« Last Edit: Wed, Jan 27, 2010 by xraven13 »

xraven13

  • Active Member
  • ***
  • Posts: 213
  • Karma: +0/-0
    • View Profile
    • GemaNeko
So i tried changing some things in FlxSound.. I see that _volumeAdjust is the value that fadeIn method adjust and pass it to updateTransform()..
So i changed it to 0 and sound is still playing!! .. I don't get how is this possible :D

xraven13

  • Active Member
  • ***
  • Posts: 213
  • Karma: +0/-0
    • View Profile
    • GemaNeko
Anyway i made my own methods in FlxSound so now its all working, but i still don't get why normal methods didnt work <.<

BearCDP

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
    • Michael Bartnett - Composer, Sound Designer, Programmer
Care to share what you did to make it work?

I wrote the music and implemented the ActionScript for on-the-beat transitions for a Global Game Jam game this past weekend and ran into the same problem. I ended up writing a helper class for fading in and out, but it was real quick and dirty and not at all optimized.

Also, does anyone else find it weird that the SoundChannel.position property is not exposed in FlxSound?
My first time working with Flex/Flash/ActionScript was with Flixel at the Jam, so it wasn't until after the fact that I was able to look at the Adobe APIs and use SoundChannel.position instead of FlxG.elapsed for counting beats.
Michael Bartnett - Music Composition, Sound Design, and Implementation

increpare

  • Member
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
FWIW I had this problem as well, and found that calling update on the FlxSound objects manually fixed it.

xraven13

  • Active Member
  • ***
  • Posts: 213
  • Karma: +0/-0
    • View Profile
    • GemaNeko
I added my own fadeIn and fadeOut methods that lowered/increased volume of music...
But it seems post above have better solution, this should be reported to Adam so that this bug is fixed =)

suibom

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
FWIW I had this problem as well, and found that calling update on the FlxSound objects manually fixed it.

Thanks increpare. Explicitly updating the sound objects in the main loop does it. Without that, the other built-in sound functions (mute, volume control) do not work either.

As far as the fade-in goes, it appears that the fade in function doesn't set the volume to 0 prior to the fade, so there is an initial burst of normal volume level sound. Checking the latest github code seems the same. I corrected with the following:
Code: [Select]
/**
* Call this function to make a sound fade in over a certain
* time interval (calls <code>play()</code> automatically).
*
* @param Seconds The amount of time the fade-in operation should take.
*/
public function fadeIn(Seconds:Number):void
{
_fadeOutTimer = 0;
_fadeInTimer = Seconds;
_fadeInTotal = _fadeInTimer;

// Added to ensure silence on fadeIn start - Sui
_volumeAdjust = 0;
updateTransform();
// -- end additional code - Sui

play();
}

Peace,
-Sui

localGhost

  • Member
  • **
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Well, you don't need to run update on them manually (though you may choose to do it), you need to add() them to the flixel engine: FlxSounds are derived from FlxObject, and as any FlxObject it will be auto update()d if added properly.

knarrenheinz

  • Member
  • **
  • Posts: 19
  • Karma: +0/-0
    • View Profile
    • CodinSoft
Greetings,

I recently ran into the same problem... the music wasn't fading in correctly.
I tracked it down to a little typing error in FlxSound:

Code: [Select]
else if(_fadeInTimer > 0)
{
_fadeInTimer -= FlxG.elapsed;
fade = _fadeInTimer/_fadeOutTotal;
if(fade < 0) fade = 0;
fade = 1 - fade;
}

Change the _fadeOutTotal to _fadeInTotal and everything should work as intended :)

Cheers
knarrenheinz

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
I wrote the music and implemented the ActionScript for on-the-beat transitions for a Global Game Jam game this past weekend and ran into the same problem. I ended up writing a helper class for fading in and out, but it was real quick and dirty and not at all optimized.

Also, does anyone else find it weird that the SoundChannel.position property is not exposed in FlxSound?
My first time working with Flex/Flash/ActionScript was with Flixel at the Jam, so it wasn't until after the fact that I was able to look at the Adobe APIs and use SoundChannel.position instead of FlxG.elapsed for counting beats.

Great idea!

I have always wanted something that would keep track of where the sound was at. It looks like it was right there. I've wanted to do something similar to Ouendan for a while now, looks like it will be possible.
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

dcfedor

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
In case anyone is still struggling with this, I noticed that using FlxG.loadSound works as expected, but objSound.loadSound does not (where objSound is a FlxSound instance).

Looking into it, it seems the FlxG.loadSound method recycles the FlxG.sounds members, which have their respective update() methods called each time FlxG updates. However, FlxSound.loadSound does not add the sound to FlxG.sounds, so their updates never get touched unless manually called.

I'm not sure that it's a bug per se, maybe more of a documentation issue. But I figured I'd post this info here in case anyone else is wondering what's happening (and wants an easy workaround, namely, use mySound = FlxG.loadSound(...)).

Hope this helps!