Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Atelier on Sat 13/06/2009 18:59:53

Title: Restart GAME, not restart MUSIC
Post by: Atelier on Sat 13/06/2009 18:59:53
Hullo.

Restarting is quite an integral part in my game. It is a one room game, and rather simple. Yet when the player restarts by pressing the space bar, it starts playing the music from the beginning again. However, I want the music to carry on playing. How can I get the game to restart without resetting the music, or can't I?

Thanks!
Title: Re: Restart GAME, not restart MUSIC
Post by: NsMn on Sat 13/06/2009 19:14:49
You can save the Music's position in a file and then seek it. Like this:


//before restarting the game
Musicpos=File.Open("Musicpos.dat", eFileWrite);

if (Musicpos == null)
 Display("Error opening musicpos file.");
else {
 Musicpos.WriteInt(GetMIDIPosition());
 Musicpos.Close();
}

//at the start of the game (After PlayMusic(); )

if(File.Exists("Musicpos.dat")){
Musicpos=File.Open("Musicpos.dat", eFileRead);

if (Musicpos == null)
 Display("Error opening musicpos file.");
else {
 SeekMIDIPosition(Musicpos.ReadInt());
}
}


Remember to replace the "SeekMIDIPosition();" and the "GetMIDIPosition();" If you have a MP3 or MOD File. And you should Delete the Musicpos.dat file if the player quits the game.
Title: Re: Restart GAME, not restart MUSIC
Post by: on Sat 13/06/2009 20:13:55
There's also the Music Continuity Module by Andrew MacCormack, though I think it essentially does the same as NsMn already posted- just as a module.