Hiya!
Now - here is my first snippet. The goal was a smooth crossfade to a new music file when jumping to the next scene.
First I had to create an entity for the music files. Actually I used two entities, but they are using the same file.
There should be a "SOUNDPANNING=FALSE" in it, but for some weird reason it crashes currently. So I chosed the position to center the entity on a 800x600 game screen. Anyway I hope this bug to be corrected soon, I'm not sure if this is a bug of my script or of WME. I will correct and edit this article as soon as I know it better.
music\music.entity :
Notice that I didn't load any soundfile yet.
In the Game.script I added two lines before changing to the scene to load the entities:
Ok. Now we jump into our scene. I wanted this scene to play "music\my_music_file.ogg" when entering.
I added these lines to the scene_init.script:
That's it ? YES! Well ok, of course there is the included function:
scripts\func_music.inc:
Now - here is my first snippet. The goal was a smooth crossfade to a new music file when jumping to the next scene.
First I had to create an entity for the music files. Actually I used two entities, but they are using the same file.
There should be a "SOUNDPANNING=FALSE" in it, but for some weird reason it crashes currently. So I chosed the position to center the entity on a 800x600 game screen. Anyway I hope this bug to be corrected soon, I'm not sure if this is a bug of my script or of WME. I will correct and edit this article as soon as I know it better.

music\music.entity :
Code: [Select]
ENTITY {
NAME="music"
CAPTION=""
ACTIVE=TRUE
X=400
Y=300
SCALABLE=FALSE
INTERACTIVE=FALSE
COLORABLE=FALSE
}Notice that I didn't load any soundfile yet.
In the Game.script I added two lines before changing to the scene to load the entities:
Code: [Select]
global music1 = Game.LoadEntity("music\music.entity");
global music2 = Game.LoadEntity("music\music.entity");
Ok. Now we jump into our scene. I wanted this scene to play "music\my_music_file.ogg" when entering.
I added these lines to the scene_init.script:
Code: [Select]
#include "scripts\func_music.inc"
PlayMusicX("music\my_music_file.ogg");That's it ? YES! Well ok, of course there is the included function:
scripts\func_music.inc:
Code: [Select]
// Music functions v0.2 (Jerrot, 2003-06-07)
global music1;
global music2;
function PlayMusicX(musicfile)
{
//---------------------------------------------------------------------
// Starts to play a musicfile. Uses a fading/crossover if another music
// is already playing.
//
// Syntax: PlayMusicX(musicfile)
// Sample: PlayMusicX("music\wintermutesong.ogg");
//---------------------------------------------------------------------
var old_channel, new_channel, counter;
// when entering a scene, we don't know, which channel entity is
// playing currently. so we have to check this here:
if (music1.IsSoundPlaying())
{
old_channel = music1;
new_channel = music2;
}
else if (music2.IsSoundPlaying())
{
old_channel = music2;
new_channel = music1;
}
else
{
// in case no music was playing (e.g. when starting the game) we just have
// to load the sound file into our channel entity and leave the function.
new_channel = music1;
new_channel.SetSoundVolume(100);
new_channel.PlaySound(musicfile,true);
return;
}
// this is a very simple crossover. counting to 100, the volume of the old_channel
// is decreased to zero, while the volume of the new_channel is increased to 100.
// the Sleep(50) command sets the speed of the crossfading.
new_channel.SetSoundVolume(0);
new_channel.PlaySound(musicfile,true);
for(counter=1; counter<=100; counter=counter+1)
{
old_channel.SetSoundVolume(100-counter);
new_channel.SetSoundVolume(counter);
Sleep(50);
}
old_channel.StopSound();
// That's it! Enjoy!
return;
}






Logged



Actually I just guessed - the entity attribute by scripting is "SoundPanning", the ".entity" file format is not documented yet and I just tried it like "active", "scalable", etc. ! 
