00:00
00:00
Newgrounds Background Image Theme

MovementalStudio just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Fading out music

965 Views | 15 Replies
New Topic Respond to this Topic

Fading out music 2012-12-21 01:11:44


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

Response to Fading out music 2012-12-21 01:25:01


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

Response to Fading out music 2012-12-21 01:27:02


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

Response to Fading out music 2012-12-21 01:32:57


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

Response to Fading out music 2012-12-21 01:43:59


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

Response to Fading out music 2012-12-21 01:50:39


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

Response to Fading out music 2012-12-21 01:53:55


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.

Response to Fading out music 2012-12-21 02:20:13


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

Response to Fading out music 2012-12-21 07:59:19


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});

Response to Fading out music 2012-12-21 11:26:08


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

Response to Fading out music 2012-12-21 11:44:10


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

Response to Fading out music 2012-12-21 16:18:39


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

Response to Fading out music 2012-12-21 16:30:52


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.

Response to Fading out music 2012-12-21 16:35:59


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

Response to Fading out music 2012-12-21 17:01:56


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!

Response to Fading out music 2012-12-24 00:43:58


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 :)


.