Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Jade on Wed 15/09/2004 13:36:44

Title: Objects/Characters animating in the background
Post by: Jade on Wed 15/09/2004 13:36:44
I need help animating objects or characters in the background.
For example...i've a stormy background and i want to add some lighting effects. I think that its not the case to do the animation with frames of the landscape so i don't know if its better to create an object or a character to make it animating randomly(in my case the lightings).

I tried creating a character but if i set him animating when the room is loaded it loop only one time and if i set it repeately execute the game is stuck in cutscene mode... ???

Any help and suggest is appreciate, thanks!
Title: Re: Objects/Characters animating in the background
Post by: Darth Mandarb on Wed 15/09/2004 15:51:09
It makes more sense to use an animated object.

This question has been asked countless times.

Darth's helpful tip: Search first!

Here's just 1 of the many threads I found (http://www.agsforums.com/yabb/index.php?topic=13546.0) which may be of use to you.

I searched for 'background animation object' and got several results.

Best of luck!
Title: Re: Objects/Characters animating in the background
Post by: Jade on Wed 15/09/2004 16:35:32
Ok thanks!Ã,  ;)

EDIT: wait...but if i want a character randomly animating how can i do it?
I tried but i always get stucked in cutscene mode... :(
Title: Re: Objects/Characters animating in the background
Post by: dreammaster on Thu 16/09/2004 01:22:20
What script are you using to animate your character. The AnimateCharacter method is non-blocking, and AnimateCharacterEx has a blocking parameter that specifies whether you want the animation to go in the background (ie. the script to continue running), or wait until the animation is finished.
Title: Re: Objects/Characters animating in the background
Post by: Jade on Thu 16/09/2004 09:28:20
I used this:
int ran=random(10);
if (ran == 0) {
SetCharacterView(Character, 6);
AnimatedCharacter(Character, 0, 0, 1);
ReleaseCharacterView(Character);
}

I put this scrip under "repeately execute" in the room i want the character move randomly.
Title: Re: Objects/Characters animating in the background
Post by: Gilbert on Thu 16/09/2004 09:33:39
As dreammaster stated, AnimateCharacter() is non-blocking, you need to make the game wait for it to stop (or just use AnimateCharacterEx() ) before using ReleaseCharacterView() (I take that SeleaseCharacterView() as a typo...): {Fixed by scummy, thanks}

int ran=random(10);
if (ran == 0) {
Ã,  SetCharacterView(Character, 6);
Ã,  AnimatedCharacter(Character, 0, 0, 1);
Ã,  while(character[Character].animating) Wait(1);
Ã,  ReleaseCharacterView(Character);
}
Title: Re: Objects/Characters animating in the background
Post by: Jade on Thu 16/09/2004 14:53:11
Actually i wasnt sure if using the "wait" thing...thank you for correcting the script...i'll try... :)
Title: Re: Objects/Characters animating in the background
Post by: Jade on Thu 16/09/2004 17:10:05
Ok...all is working...but the annoying remaining thing is that every time the character start animating randomly it stop the other actions.
I mean...it work like a little cutscene...is there a way to make him animating and being indipendend from other actions in the game?
For example...when i'm talking to another character in the room...the script for animating the other objects doesnt work... :-[
Title: Re: Objects/Characters animating in the background
Post by: Albert Cuandero on Thu 16/09/2004 19:38:52
Quotebut the annoying remaining thing is that every time the character start animating randomly it stop the other actions

but that's waht you told it to do...

it's this line:

while(character[Character].animating) Wait(1);

=AGS waits until the animation is over...
Title: Re: Objects/Characters animating in the background
Post by: Scorpiorus on Thu 16/09/2004 22:35:05
Yeah, so putting "if (character[Character].animating == 0)" within the repeatedly execute should do the trick:

repeatedly execute:


// if Character is not animating...
if (character[Character].animating == 0) {

Ã,  Ã,  ReleaseCharacterView(Character);

Ã,  Ã,  int ran=random(10);

Ã,  Ã,  if (ran == 0) {
Ã,  Ã,  SetCharacterView(Character, 6);
Ã,  Ã,  AnimatedCharacter(Character, 0, 0, 0);
Ã,  Ã,  }
}
Title: Re: Objects/Characters animating in the background
Post by: dreammaster on Fri 17/09/2004 00:58:29
Slight correction to Scorpiorus's code fragment - one trouble is that the animation is only restarted with a 10% probably. But your test condition was if .animating == 0, which means that it'd keep calling ReleaseCharacterView.

Perhaps  not a critical problem, but it's a good practice to set up flags so that such "ending" conditions only get called once. Otherwise, as your code becomes more complicated, there could be weird side-effects.
Title: Re: Objects/Characters animating in the background
Post by: Gilbert on Fri 17/09/2004 02:58:19
I'll suggest this fix:

move
int ran;
to the top of the script, so it's not redeclared everytime the repeatedly_execute() script is run.

Then, in repeatedly_execute():

if (ran==0) {
Ã,  Ã,  if (character[Character].animating==0) {
        // if Character just stopped animating
Ã,  Ã,  Ã,  Ã,  ReleaseCharacterView(Character);
Ã,  Ã,  Ã,  Ã,  ran=1; //So to trigger random() again next game loop
Ã,  Ã,  }
} else {
    // if Character is not animating...
Ã,  Ã,  ran=random(10);
Ã,  Ã,  if (ran == 0) {
Ã,  Ã,  Ã,  SetCharacterView(Character, 6);
Ã,  Ã,  Ã,  AnimatedCharacter(Character, 0, 0, 0);
Ã,  Ã,  }
}


Edit: oops found that the former codes may not work as expected.
Title: Re: Objects/Characters animating in the background
Post by: Scorpiorus on Fri 17/09/2004 05:50:34
Quote from: dreammaster on Fri 17/09/2004 00:58:29PerhapsÃ,  not a critical problem, but it's a good practice to set up flags so that such "ending" conditions only get called once. Otherwise, as your code becomes more complicated, there could be weird side-effects.
Yep, good point. Here, as you say, it's not that critical since the character's view is only released when he isn't animating. And since he isn't to move ReleaseCharacter shouldn't have a side effect. But yeah practically it's a way to go. Gilbert's code will care about it. The only thing left to do is to increase a value within random(...), because otherwise the animation will be run almost instantly. :)
Title: Re: Objects/Characters animating in the background
Post by: Jade on Fri 17/09/2004 19:45:50
I fixed the problem...thank you all!!!  :)