Be a Supporter!
Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 12
Artist
Fading out music Dec. 21st, 2012 @ 01:11 AM Reply

Hey guys! Fate here, as always. Let's get down to business cause I'm kinda in a hurry xD

I created a start menu for my game, and it plays fine and dandy. Thing is, when the menu appears, BG music starts playing (that's fine, it was intentional), here's the code for the BG music play:

var BGmusic:Sound = new mainsoundtrack();
var MusicChannel:SoundChannel = new SoundChannel();

addEventListener(Event.ENTER_FRAME, asignarcanal01);

function asignarcanal01(event:Event):void{

MusicChannel = BGmusic.play(0,9999);
this.removeEventListener(Event.ENTER_FRAME, asignarcanal01);

}

After some basic animation passes and the buttons appear, the game stops until the player picks a button. When he does (in this case, the start game button), this code enters into action:

var startgame:Boolean = false
var snd:Sound = new gamestart();

startbutton.addEventListener(MouseEvent.CLICK, start01);

function start01 ( m:MouseEvent )
{
startgame = true;
snd.play();
play();
}

Everything is going as planned. Once the start button is clicked, it emmits a "start" sound and the menu begins to fade to black to let the game begin. However, obviously, the BG music keeps playing full force as the menu fades. How do I manage to fade out the music once a button is chosen? (I mean fading out until the last frame of the menu, not just simply stop on an abrupt halt)

Sorry for the rushed explanation, but as I said, I'm kinda in a hurry, but I wanted to leave this here so maybe someone can answer this and have a solution for when I get back xD

Thanks as always for the wisdom, oh wise ones -.-

Fate out!!!

Fading out music

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to Fading out music Dec. 21st, 2012 @ 01:25 AM Reply

Straight from the Adobe docs inside FD (the playerglobal.swc)

public final class SoundChannel extends EventDispatcher
{

	 * The current amplitude (volume) of the left channel, from 0 (silent) to 1 (full amplitude).
	public function get leftPeak () : Number;

	 * The current amplitude (volume) of the right channel, from 0 (silent) to 1 (full amplitude).
	public function get rightPeak () : Number;

Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to Fading out music Dec. 21st, 2012 @ 01:27 AM Reply

also, because i'm an idiot and forgot to look for setters for the left and right peaks:

/**
		 * The SoundTransform object assigned to the sound channel. A SoundTransform object
		 * includes properties for setting volume, panning, left speaker assignment, and right
		 * speaker assignment.
		 * @langversion	3.0
		 * @playerversion	Flash 9
		 * @playerversion	Lite 4
		 * @refpath
		 */
		public function get soundTransform () : flash.media.SoundTransform;
		public function set soundTransform (sndTransform:SoundTransform) : void;

the SoundTransform class is very straightforward.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 12
Artist
Response to Fading out music Dec. 21st, 2012 @ 01:32 AM Reply

If I'm not mistaken, this kind of explains how to alter the sound... but it doesn't make it progressive. I need to "fade out" the music channel, not just mute it. (Again, I might be missing the point... I'm a toddler at AS3, so just pasting codes isn't much of a heads up for me... It still looks like alien language to me xD)

I appreciate the help though. I'm just slow for this kinda thing... That's why I usually stick to illustration and art production xD

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Fading out music Dec. 21st, 2012 @ 01:43 AM Reply

Use TweenLite or a Timer event or something to constantly apply a new SoundTransform with the volume property ranging from 1-0.

var mySound:Sound = new Sound("whatever");
var currentVol:int = 1;
var myChannel:SoundChannel = mySound.play();

var myFadeTimer:Timer = new Timer(30, 0);
myFadeTimer.addEventListener(TimerEvent.TIMER, fadeSound);
myFadeTimer.start();

function fadeSound(e:TimerEvent):void
{
currentVol -= .01;
var t:SoundTransform = new SoundTransform(currentVol);
myChannel.soundTransfrom = t;
if (currentVol <= 0)
{
myFadeTimer.stop();
}
}

If you can't figure it out PM me, it's surprisingly complex.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 12
Artist
Response to Fading out music Dec. 21st, 2012 @ 01:50 AM Reply

At 12/21/12 01:43 AM, MintPaw wrote: Use TweenLite or a Timer event or something to constantly apply a new SoundTransform with the volume property ranging from 1-0.

var mySound:Sound = new Sound("whatever");
var currentVol:int = 1;
var myChannel:SoundChannel = mySound.play();

var myFadeTimer:Timer = new Timer(30, 0);
myFadeTimer.addEventListener(TimerEvent.TIMER, fadeSound);
myFadeTimer.start();

function fadeSound(e:TimerEvent):void
{
currentVol -= .01;
var t:SoundTransform = new SoundTransform(currentVol);
myChannel.soundTransfrom = t;
if (currentVol <= 0)
{
myFadeTimer.stop();
}
}

If you can't figure it out PM me, it's surprisingly complex.

I think this bit of code, along with some modifications, could do the trick... I'm not sure, but for what I grasp about it, I think I can make it fit inside my already built code...

I'll try it tomorrow and post the outcome ^^ Thanks for the support.

Fading out music

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Fading out music Dec. 21st, 2012 @ 01:53 AM Reply

The SoundManager lib makes playing/stopping/muting/changing volume of sounds very easy. Not sure if you can fit learning how it works and changing everything into your timeframe, but it's extremely useful to learn for the future.

Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 12
Artist
Response to Fading out music Dec. 21st, 2012 @ 02:20 AM Reply

At 12/21/12 01:53 AM, MSGhero wrote: The SoundManager lib makes playing/stopping/muting/changing volume of sounds very easy. Not sure if you can fit learning how it works and changing everything into your timeframe, but it's extremely useful to learn for the future.

I'll keep that in mind, thanks. ;D

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Fading out music Dec. 21st, 2012 @ 07:59 AM Reply

At 12/21/12 01:43 AM, MintPaw wrote: Use TweenLite
var mySound:Sound = new Sound("whatever");
var myChannel:SoundChannel = mySound.play();
 
TweenLite.to(myChannel, 1, {volume:0});
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to Fading out music Dec. 21st, 2012 @ 11:26 AM Reply

At 12/21/12 01:53 AM, MSGhero wrote: The SoundManager lib makes playing/stopping/muting/changing volume of sounds very easy. Not sure if you can fit learning how it works and changing everything into your timeframe, but it's extremely useful to learn for the future.

I r built a SoundManager class, too :3
but I forgot to add volume functions to it. Herp.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Fading out music Dec. 21st, 2012 @ 11:44 AM Reply

At 12/21/12 07:59 AM, milchreis wrote:
At 12/21/12 01:43 AM, MintPaw wrote: Use TweenLite
var mySound:Sound = new Sound("whatever");
var myChannel:SoundChannel = mySound.play();

TweenLite.to(myChannel, 1, {volume:0});

Actually I'm pretty sure that doesn't work, you need to re-apply a SoundTransform onUpdate.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 12
Artist
Response to Fading out music Dec. 21st, 2012 @ 04:18 PM Reply

Well, thanks for the hints and tips everybody ^^ I managed to create a bit of code quite simple that did the trick without problems. Here it is:

var currentVol:Number = 1;
var myFadeTimer:Timer = new Timer(25, 0);
var MusicChannelTransform = new SoundTransform();

myFadeTimer.addEventListener(TimerEvent.TIMER, fadeMusic);
function fadeMusic (e:TimerEvent):void{

if (currentVol>=.01){

currentVol = currentVol-0.01
MusicChannelTransform.volume = currentVol;
MusicChannel.soundTransform = MusicChannelTransform;

}

else{
myFadeTimer.stop();
this.removeEventListener(Event.ENTER_FRAME, fadeMusic);
}

}

myFadeTimer.start();

Yeah, it was simple to write, but I had to mix a little out of everything to figure it out xD Thanks again bros, I wouldn't have made it without your help :D

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Fading out music Dec. 21st, 2012 @ 04:30 PM Reply

At 12/21/12 11:44 AM, MintPaw wrote: Actually I'm pretty sure that doesn't work, you need to re-apply a SoundTransform onUpdate.

I'm pretty sure it works, yet I'm too lazy to try.

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Fading out music Dec. 21st, 2012 @ 04:35 PM Reply

At 12/21/12 04:18 PM, Fatelogic wrote: Code and junk

Ok, a couple things there.

"currentVol = currentVol-0.01" can be written as "currentVol -= .01"

"this.removeEventListener(Event.ENTER_FRAME, fadeMusic);" is all wrong, you have to remove the event that you added, so it'd be:
"myFadeTimer.removeEventListener(TimerEvent.TIMER, fadeMusic);"
It's really a miracle that doesn't give you an error.

Also variable don't normally start with capital letters.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 12
Artist
Response to Fading out music Dec. 21st, 2012 @ 05:01 PM Reply

At 12/21/12 04:35 PM, MintPaw wrote:
Ok, a couple things there.

"currentVol = currentVol-0.01" can be written as "currentVol -= .01"

"this.removeEventListener(Event.ENTER_FRAME, fadeMusic);" is all wrong, you have to remove the event that you added, so it'd be:
"myFadeTimer.removeEventListener(TimerEvent.TIMER, fadeMusic);"
It's really a miracle that doesn't give you an error.

Also variable don't normally start with capital letters.

What can I say... it works perfectly :s

Besides, aside from the event removal... The rest sounds a bit like nitpicking... I don't need it to be scientifically perfect, I need it to get the work done... and it does pretty well actually :D This project started as an art poll, so it's natural that it's source isn't professionally coded... the professionalism is in the imagery (well, that's what I do for a living, so yeah, kinda obvious). All the programming and such is just "secondary added value" as means to reach a wider audience (and look at my works actually moving, which is kinda cool).

And let's face it... hentai games usually are nothing more than animated sequences put together via simple buttons... the interactive value of these kind of games is the bare minimum required for it to be called "a game".

So yeah, the code might be "techincally flawed", but as long as it doesn't reflects a detriment in the playing experience, it's the same as a perfect code. It gets the work done without dragging problems along the ride.

Thanks for the tips, everybody!

64base
64base
  • Member since: Apr. 18, 2012
  • Offline.
Forum Stats
Member
Level 02
Programmer
Response to Fading out music Dec. 24th, 2012 @ 12:43 AM Reply

At 12/21/12 05:01 PM, Fatelogic wrote:
What can I say... it works perfectly :s

Besides, aside from the event removal... The rest sounds a bit like nitpicking... I don't need it to be scientifically perfect, I need it to get the work done... and it does pretty well actually :D This project started as an art poll, so it's natural that it's source isn't professionally coded... the professionalism is in the imagery (well, that's what I do for a living, so yeah, kinda obvious). All the programming and such is just "secondary added value" as means to reach a wider audience (and look at my works actually moving, which is kinda cool).

And let's face it... hentai games usually are nothing more than animated sequences put together via simple buttons... the interactive value of these kind of games is the bare minimum required for it to be called "a game".

So yeah, the code might be "techincally flawed", but as long as it doesn't reflects a detriment in the playing experience, it's the same as a perfect code. It gets the work done without dragging problems along the ride.

Thanks for the tips, everybody!

I'm not saying this to discourage you or hurt your feelings but I would use my artistic skills on something much more valuable. Why not tell an original and touching story or a comedic parody rather than a perverted anime only there to please the sexual desires of some nerds jacking off to it?

I know many of my mates argue with me about "sex = art" and so it may be, but pornography definitely isn't. Materialism also definitely isn't.

But this is my opinion, I have no problems with what you want to do or your choice, I just hope you can use your talent for something better :)


.