Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Michigami on Wed 25/02/2009 07:39:14

Title: synching animation and music, or stopping it
Post by: Michigami on Wed 25/02/2009 07:39:14
to begin, i'm using 3.0.
i've made a DDR machine for my game.  not a working minigame yet, might never be, it's currently just a geek moment of having "ye olde dancing game machine" in the tavern, and it plays actual ddr song midis on random.

the problem is, i want the animation for the machine to loop, and to stop when the song ends, and also to stop the song when it's finished instead of looping as it does now.  there's also a little animation of the player dancing on the machine that also needs to start and stop with the music.

at the moment, i've got it set up as follows:
Quote
function oddrmachine_Interact()
{
  player.Walk(82,  120,  eBlock);
  StopMusic();
  oddrmachine.SetView(11);
  oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  int ran=Random(10);
  if (ran==0){oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(100);}
  else if (ran==1) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(101);}
  else if (ran==2) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(102);}
  else if (ran==3) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(103);}
  else if (ran==4){ oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(104);}
  else if (ran==5) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(105);}
  else if (ran==6) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(106);}
  else if (ran==7) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(107);}
  else if (ran==8) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(108);}
  else if (ran==9) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(109);}
  else if (ran==10) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(110);}
  else {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(110);}
}

i haven't added the dancing person's code yet because i wanted to solve the loop and synch problem first.  i haven't added anything that says "stop" either because it spits errors left and right with every piece of code i try to add beyond this.

i'd also like to know if it's possible to condense the animations into one function to be called repeatedly instead of having to insert the entire script over and over, and how would i go about doing that?

(http://i123.photobucket.com/albums/o305/michigami/yeoldeddr.gif)
Title: Re: synching animation and music, or stopping it
Post by: Gilbert on Wed 25/02/2009 08:20:36
Suggestions:
1. Before you start playing a DDR track, use SetMusicRepeat() to disable looping of BG music.
2. Use a variable to track whether there is a DDR track being played.
3. In repeatedly_execute() (or in repeatedly_execute_always(), depending on your needs) check whether a DDR track is being played, if it's being played and the track has stopped, stop everything.

So (untested):


int DDRPLAYING=0;

function oddrmachine_Interact()
{
  player.Walk(82,  120,  eBlock);
  StopMusic();
  SetMusicRepeat(0);
  DDRPLAYING=1;
  oddrmachine.SetView(11);
  oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  int ran=Random(10);
  if (ran==0){oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(100);}
  else if (ran==1) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(101);}
  else if (ran==2) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(102);}
  else if (ran==3) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(103);}
  else if (ran==4){ oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(104);}
  else if (ran==5) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(105);}
  else if (ran==6) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(106);}
  else if (ran==7) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(107);}
  else if (ran==8) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(108);}
  else if (ran==9) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(109);}
  else if (ran==10) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(110);}
  else {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(110);}
}


Also:

function repeatedly_execute(){
  if (DDRPLAYING) {
    if (IsMusicPlaying ()==0){
      DDRPLAYING=0;
      oddrmachine.StopAnimating();
      /* Add codes to restore playing of original BGM and reset music repeat to true here if needed */
    }
  }
}

Title: Re: synching animation and music, or stopping it
Post by: Khris on Wed 25/02/2009 11:17:22
Instead ofint ran=Random(10);
  if (ran==0){oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(100);}
  else if (ran==1) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(101);}
  else if (ran==2) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(102);}
  else if (ran==3) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(103);}
  else if (ran==4){ oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(104);}
  else if (ran==5) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(105);}
  else if (ran==6) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(106);}
  else if (ran==7) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(107);}
  else if (ran==8) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(108);}
  else if (ran==9) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(109);}
  else if (ran==10) {oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  PlayMusic(110);}


you can use
  oddrmachine.Animate(1, 5, eRepeat, eNoBlock);
  Playmusic(100+Random(10));


It's a bit shorter. :=
Title: Re: synching animation and music, or stopping it
Post by: Gilbert on Wed 25/02/2009 12:25:46
It could be, however, as he mentioned the codes are not all settled yet, there is a possibility that he'll add tweaks, like playing different animations with different musics, among other stuff. That's why I don't recommend shortening the codes at this moment.
Title: Re: synching animation and music, or stopping it
Post by: Michigami on Thu 26/02/2009 04:10:44
thank you so much, works beautifully with a little tweaking for the extra animations now.

and the shortened one came in handy for another random set i had in another room, so thanks again.

(http://i123.photobucket.com/albums/o305/michigami/michidancin.gif) PS, da miche is a She, but still appreciates the help.  ^_^!
Title: Re: synching animation and music, or stopping it
Post by: Gilbert on Thu 26/02/2009 05:04:21
Grad to hear that the problem is sorted.

Quote from: Michigami on Thu 26/02/2009 04:10:44
PS, da miche is a She, but still appreciates the help.  ^_^!

Sorry... :-[

I'm just lazy to check people's profiles.  ;D