Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: joaomesq on May 23, 2005, 08:27:28 PM

Title: waiting for animation to finish
Post by: joaomesq on May 23, 2005, 08:27:28 PM
I'm having some trouble trigging character movement after a sprite animation. The thing is the character pushes a button and the door opens completely and after the character turns to it.

I tried like this (in the button script)

Code: [Select]
var porta_anim = Scene.GetNode("porta_placeholder");
porta_anim.SetSprite("scenes\cela1\sprites\porta\porta_abrir.sprite");
var frames_porta = porta_anim.GetSpriteObject();
WaitFor(frames_porta);
actor.TurnTo(porta_anim);

But the character turns before finishing the door animation

Then I tried an old Director technique to control video...
 
Code: [Select]
var porta_anim = Scene.GetNode("porta_placeholder");
porta_anim.SetSprite("scenes\cela1\sprites\porta\porta_abrir.sprite");
var frames_porta = porta_anim.GetSpriteObject();
while(true)
{
if(frames_porta.CurrentFrame == frames_porta.NumFrames)
{break;}
}
actor.TurnTo(porta_anim);

It crashed...

To test the return values of CurrentFrame and NumFrames I used this...

Code: [Select]
var porta_anim = Scene.GetNode("porta_placeholder");
porta_anim.SetSprite("scenes\cela1\sprites\porta\porta_abrir.sprite");
var frames_porta = porta_anim.GetSpriteObject();
Game.Msg(frames_porta.NumFrames);
for(var i = 0; i < 20; i= i +1)
{
Game.Msg(frames_porta.CurrentFrame);
}
actor.TurnTo(porta_anim);

NumFrames returns 15 (which is correct), CurrentFrame returns 0 even when the animation is playing.

Completely lost, here...
Title: Re: waiting for animation to finish
Post by: Mnemonic on May 23, 2005, 08:37:11 PM
You should use PlayAnim instead. It blocks the script execution until the animation finishes:

Code: [Select]
var porta_anim = Scene.GetNode("porta_placeholder");
porta_anim.PlayAnim("door_opening.sprite");
porta_anim.SetSprite("door_open.sprite");
actor.TurnTo(porta_anim);

While your code would work, in theory, you'd have to call the Sleep() command in the loop, otherwise the control isn't returned back to the engine and it doesn't have a chance to update the animation in the meanwhile.
Title: Re: waiting for animation to finish
Post by: joaomesq on May 24, 2005, 11:40:35 AM
It worked.

My assumption was that it had to be some method in the Sprite object.
And besides because the animation plays automatically I would never thought of that.

Thank you.