Fade Music when press the START button in Main Menu... (SOLVED)

Started by ............................................................, Sun 02/09/2012 01:32:09

Previous topic - Next topic
Hi ... im tryed various type of combinations ... reading 100 threads ... but i can't get the solution of this question ....
Well this is the story .... Imagine a Main Menu with a beautifull melody and a nice big START GAME button .... the nice thing is if the music fade out after pressing the START button, first you enter the playable romm .... I tryed to use this script ( working for fading ) .... test number one:

Im put this lines in Global Script

{
AudioChannel* chan = aBeloved.Play();
chan.Volume = 80;
int trans = chan.Volume;
  while (trans > 0) {
  trans--;
  chan.Volume = trans;
  Wait(10);
}
}

Audio start and fade out ONLY after pressing the START button .....
Test number 2:
If I put this two line in Global Script

{
AudioChannel* chan = aBeloved.Play();
chan.Volume = 80;
}

And the others under

function StartButton_OnClick(GUIControl *control, MouseButton button)
{
int trans = chan.Volume;
  while (trans > 0) {
  trans--;
  chan.Volume = trans;
  Wait(10);
}
}

The Output Windows give me this error: GlobalScript.asc(528): Error (line 528): undefined symbol 'chan'
Im tryed with room 1 and room 2 but when i split the lines give me the same error .... if i use all the lines together in a room the music start but all is blocked untill the music is finished ( with the fade out )

I want only the music start playing when the START page appear and fade out after pressing the start button ........ someone know how i can do it????

Thanks........

Khris

You need to read up on room events.
To start music when the first room is loaded, add the room's "player enters before fadein" event. Then put the code in the function. It should look like this:
Code: ags
// room script of first room

function room_Load() {
  AudioChannel* chan = aBeloved.Play();
  chan.Volume = 80;
}

Note that you can't simply paste this into the room script, you must link the function to the event first via the event panel (in the room editor, make sure the room itself is selected in the dropdown menu, then click the lightning bolt icon).

As for fading out the music: you set the volume to 80, so the loop brings it down to 0 in 80 steps, each taking a quarter of a second. That's 20 seconds of the player staring at the start screen after they have pressed the "start game" button.

(Also, if you post code, please don't omit the function's name so we can follow what you're doing.)

Thanks for the reply .... ( yep...i know about the event ) ... but i don't want the music fade out in the start page ..... only if you press start the music must to fade out ... this is what i want ... as long as we remain in the start page the music should continue to play ....
If i put this line in ROOM_AFTERFADEIN the music continue when im going in the 2nd room.... i can stop it ... but is not very nice......

Khris

I only told you how to start music when the player enters a room. Your last post doesn't make sense, given what I wrote in my previous one.

You still need the fade out code in StartButton_OnClick, of course, in case you thought my meager two lines solve all your problems.

Well...thanks again for the patience ....

Im explain again ( sorry..my english is not very good  (roll) )
If im put the script in room load AGS tell me i can't and to put it in the Room_AfterFadeIn....if i put all the script in ROOM 1 .......

function room_AfterFadeIn()
{
AudioChannel* chan = aBeloved.Play();
chan.Volume = 80;
int trans = chan.Volume;
  while (trans > 0) {
  trans--;
  chan.Volume = trans;
  Wait(10);
}
}
.....the music start and after a time fade out automatically ( i don't want this )...Because i want the music start fade out after i press a button. I thinked "the command for the fade out should be under the button's event" but the script for start the music can't stay under it ... or i need to press the button to start the music.....right?!?!?
Im tryed this:
IN ROOM 1

function room_AfterFadeIn()
{
AudioChannel* chan = aBeloved.Play();
chan.Volume = 80;
}

and in GLOBAL SCRIPT

function StartButton_OnClick(GUIControl *control, MouseButton button)
{
Mouse.UseModeGraphic(eModePointer);
Wait(40);
gMainMenu.Visible=false;
gIconbar.Visible=true;
cRoby.ChangeRoom(2, 512, 750);
int trans = chan.Volume;
  while (trans > 0) {
  trans--;
  chan.Volume = trans;
  Wait(10);
}
}
....but don't work ...when im test the game ( Run ) the AGS say "error: GlobalScript.asc(528): Error (line 528): undefined symbol 'chan'" .... i can't split the script or AGS don't remember i called the channel "chan" and don't recognize it........My question ....how to resolve this ( if is possible ) ??? Make the music start with the first page and fade out ONLY after i press the button !?!?!??!?!


Khris

Ok I see the problem now, but please stop putting all the code into the AfterFadein functon, that's obviously not what you want.

The basic method is fine, you just need to turn chan into a global pointer.

Go to the "Gobal variables" pane, right click the empty list, and add a new variable. Call it start_chan and as type, choose "AudioChannel*".

Then use this:
Code: ags
 // in room_AfterFadeIn
  start_chan = aBeloved.Play();
  start_chan.Volume = 80;

// in the button's function:
    ...
    start_chan.Volume = trans;
    ...

Aaaaaaaaah !!!!! Thank you very much ..... now working perfectly  (laugh) .... but I put the script in the second room first_load ... now after you click the button ... the screen and the music fade out together and appear the second room .... ( if I left the script in the press_button I had to wait for the timer to finish before can passing into the other room .... ) .... thanks again ....

Khris

Yes. If I may quote myself :-D
Quote from: Khris on Sun 02/09/2012 02:15:07That's 20 seconds of the player staring at the start screen after they have pressed the "start game" button.

SMF spam blocked by CleanTalk