Wintermute Engine Forum
Wintermute Engine => Technical forum => Topic started 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)
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...
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...
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...
-
You should use PlayAnim instead. It blocks the script execution until the animation finishes:
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.
-
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.