Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: waiting for animation to finish  (Read 3531 times)

0 Members and 1 Guest are viewing this topic.

joaomesq

  • Teacher / Game Designer
  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 44
    • View Profile
    • Nó Górdio
waiting for animation to finish
« 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...
Logged
Crisis is just another word for opportunity

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: waiting for animation to finish
« Reply #1 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.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

joaomesq

  • Teacher / Game Designer
  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 44
    • View Profile
    • Nó Górdio
Re: waiting for animation to finish
« Reply #2 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.
Logged
Crisis is just another word for opportunity
 

Page created in 0.018 seconds with 22 queries.