Character animation in Background

Started by Caracal, Sun 04/03/2012 18:38:59

Previous topic - Next topic

Caracal

Hello everyone.
I am now, after a long time, facing a new problem. In order to add more life to my game environment I would like the NPCs to perform a little animation every once in a while. For that I came up with something like this:

function room_Load()
{
SetTimer(1, 450);
}

function room_RepExec()
{
if (IsTimerExpired(1)){
cSabine.LockView(VSABINE);
cSabine.Animate(1, 0, eOnce, eBlock, eForwards);
cSabine.UnlockView();
cSabine.LockView(VSABINE);
cSabine.Animate(0, 0, eOnce, eNoBlock, eForwards);
cSabine.UnlockView();
SetTimer(1, 450);
}
}
This works splendid, the only problem: the animation causes a cut scene in which the player can not control anything. This is really quite bothering. And furthermore it prevents me from having characters performing actions continuously.
I know that there is a “SayBackground” function, but have not found something like AnimateBackground.
Thanks for any constructive thoughts and ideas in advance!

NickyNyce

#1
Just a thought, you could set the NPC's Idel view to show this animation that you speak of. Just put this in your global script under Game start.

 cSabine.SetIdleView(5, 450); //adjust the last number for however long it takes for the Idel animation to start, the first is the view #

You can also put delays on your frames in your view also. There was another thread about this not too long ago, look back a page or two.

Miglioshin

#2
I think that this is your main problem

Quote from: Caracal on Sun 04/03/2012 18:38:59

cSabine.Animate(1, 0, eOnce, eBlock, eForwards);


but if you insert the eNoBlock AGS will play the second animation in the same loop so you will actually see only the second animation.

Try something like this, you need two booleans and you need to check if your cSabine isn't actually animating before starting a new animation loop:

bool Sabine_first_anim = false;
bool Sabine_played = false;

Since you need them only in the current room you can insert them at the top of the room script (instead of the global variables panel)

Code: ags

function room_RepExec()
{
  if (IsTimerExpired(1)){
    if(!cSabine.Animating && Sabine_first_anim == true) //The first animation has played
    {
     cSabine.Animate(0, 0, eOnce, eNoBlock, eForwards);
     Sabine_played = true;
     }
    
    if(!cSabine.Animating && Sabine_first_anim == false) //The first animation hasn't played
     cSabine.LockView(VSABINE);
     cSabine.Animate(1, 0, eOnce, eNoBlock, eForwards);
     Sabine_first_anim = true
    }
    
   if(Sabine_first_anim == true && Sabine_played == true)// Both animation have played
     {
      SetTimer(1, 450);
      Sabine_first_anim = false;
      Sabine_played = false;
      cSabine.UnlockView();
     }
   }
}



I didn't tested it but this should do.

Another hint I cand lend you is to envelop those line in a function outside the room repeatedly execute and make a function call inside repeatedly execute, so your functions won't become to messy ;)

Let us know

Cheers

Caracal

Quote from: NickyNyce on Sun 04/03/2012 21:00:27
Just a thought, you could set the NPC's Idel view to show this animation that you speak of. Just put this in your global script under Game start.

 cSabine.SetIdleView(5, 450); //adjust the last number for however long it takes for the Idel animation to start, the first is the view #

You can also put delays on your frames in your view also. There was another thread about this not too long ago, look back a page or two.

Hmm. Ags comes up with the "Uncexpected cSabine.SetIdeleView(5,450);" Maybe i am not puting it right. With global script you mean the script in which i have the Guis ect. (because in the side bar there is a global script asc and a global script ash)
And how do i create the game start function? is there a certain button for that (like the "before room load")

Caracal

Quote from: Miglioshin on Sun 04/03/2012 21:01:05
I think that this is your main problem

Quote from: Caracal on Sun 04/03/2012 18:38:59

cSabine.Animate(1, 0, eOnce, eBlock, eForwards);


but if you insert the eNoBlock AGS will play the second animation in the same loop so you will actually see only the second animation.

Try something like this, you need two booleans and you need to check if your cSabine isn't actually animating before starting a new animation loop:

bool Sabine_first_anim = false;
bool Sabine_played = false;

Since you need them only in the current room you can insert them at the top of the room script (instead of the global variables panel)

Code: ags

function room_RepExec()
{
  if (IsTimerExpired(1)){
    if(!cSabine.Animating && Sabine_first_anim == true) //The first animation has played
    {
     cSabine.Animate(0, 0, eOnce, eNoBlock, eForwards);
     Sabine_played = true;
     }
    
    if(!cSabine.Animating && Sabine_first_anim == false) //The first animation hasn't played
     cSabine.LockView(VSABINE);
     cSabine.Animate(1, 0, eOnce, eNoBlock, eForwards);
     Sabine_first_anim = true
    }
    
   if(Sabine_first_anim == true && Sabine_played == true)// Both animation have played
     {
      SetTimer(1, 450);
      Sabine_first_anim = false;
      Sabine_played = false;
      cSabine.UnlockView();
     }
   }
}



I didn't tested it but this should do.

Another hint I cand lend you is to envelop those line in a function outside the room repeatedly execute and make a function call inside repeatedly execute, so your functions won't become to messy ;)

Let us know

Cheers

Whow thats a lot!
Well first of all i have to say thank you! The Function does work at the first sight. Only that the character remains locked in the last animation loop panel and does not change even if the timer is expired again.
Basically -the character is in this animation taking a deep breath from a cigarette and then blowing out the fog- cSabine remains frozen in the "blow out" frame. And does not do anything after that. Even if i activate her speech view in the game -which still works good- she goes back to the frozen frame.
I will look over the function code you gave me myself. But to be completely honest: right now i am pretty stunned, since i dont really understand it right away. ^///^
But thank you very much!

NickyNyce

#5
It's the bottom global script, It's the asc one. The game start function is already there, it's a couple of functions down I think, just place the code inside it. This may not be the best way of going about your problem, but it's something for you to think about  ;)

Also...you have a typo with SetIdelView. You have SetIdeleView

Miglioshin

#6
Hmmm...

I also had troubles re-setting the same timer that has just expired in the IsTimerExpired call, so you can have an easy workaround with this:

Code: ags


int time = 0; //in the Room_Load function so the time will be set to 0 each time you enter the room

//It's not a bad idea also to set the normal cSabine view each time you enter the room
//just in case you leave the room while cSabine is animating...

function room_RepExec()
{
  time++;
  if(time > 450)
  {    
    if(!cSabine.Animating && Sabine_first_anim == true) //The first animation has played
     {
      cSabine.Animate(0, 0, eOnce, eNoBlock, eForwards);
      Sabine_played = true;
      }
    
     if(!cSabine.Animating && Sabine_first_anim == false && time) //The first animation hasn't played
    {
     cSabine.LockView(VSABINE);
     cSabine.Animate(1, 0, eOnce, eNoBlock, eForwards);
     Sabine_first_anim = true;
    }
    
   if(!cSabine.Animating && Sabine_first_anim == true && Sabine_played == true)// Both animation have played
     {
      Sabine_first_anim = false;
      Sabine_played = false;
      time = 0;
      cSabine.UnlockView(); //if UnlockView doesn't work for some reason just replace with cSabine.LockView(the_normal_view)
     }
  }

}



Maybe this is better.

Let us know

Cheers

Miglioshin


Caracal

Quote from: Miglioshin on Tue 06/03/2012 22:27:28
Quote from: NickyNyce on Mon 05/03/2012 15:12:25
Also...you have a typo with SetIdelView.

It's "SetIdleView" ;)

Cheers :)

JES! Thats it! Finally thank you so much!

SMF spam blocked by CleanTalk