Restart GAME, not restart MUSIC

Started by Atelier, Sat 13/06/2009 18:59:53

Previous topic - Next topic

Atelier

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!

NsMn

#1
You can save the Music's position in a file and then seek it. Like this:
Code: ags


//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.

Ghost

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.

SMF spam blocked by CleanTalk