Wintermute Engine Forum
Wintermute Engine => Technical forum => Topic started by: Stucki on January 06, 2008, 11:26:56 PM
-
Hello again.
i am trying to control the delay of to sprites with this script. But it doesnt change the delay at all ....
here is the script:
#include "scripts\base.inc"
////////////////////////////////////////////////////////////////////////////////
var zufall,i,Frame;
var rad_1 = Scene.GetNode ("rad_1");
var rad_2 = Scene.GetNode ("rad_2");
Sleep (2000);
while (true)
{
Sleep (Random(100,4000));
rad_2.SetSprite ("scenes/Kapitel_4/Torhaus/rad_2.sprite");
zufall=Random (10,120);
for( i=0; i<rad_2.NumFrames; i=i+1)
{
Frame = rad_2.GetFrame(i);
Frame.Delay = zufall;
}
rad_2.Active=true;
rad_1.Active=false;
Sleep (2200);
Sleep (Random(100,4000));
rad_1.SetSprite ("scenes/Kapitel_4/Torhaus/rad_1.sprite");
zufall=Random (10,120);
for( i=0; i<rad_1.NumFrames; i=i+1)
{
Frame = rad_1.GetFrame(i);
Frame.Delay = zufall;
}
rad_1.Active=true;
rad_2.Active=false;
Sleep (2200);
}
any ideas what might be wrong with it ?
-
it seems wrong to me.
I can't test it now, but you're questioning node as if it was sprite.
first of all, to access sprite you'd need to do:
var rad_sprite = rad2.GetSpriteObject();
But there's no delay or Delay in the interface to sprite object (at least not in the documentation).
There's much more elegant solution:
Sprite has a low level event FrameChanged. Attach a script to your sprite in the sprite editor and register
on "FrameChanged"
{
this.Pause();
Sleep(Random(100,4000));
this.Play();
}
How does this sound?
Edit: maybe it's necessary to pause the sprite before sleep. oops.
-
But there's no delay or Delay in the interface to sprite object (at least not in the documentation).
Yes, it's a property of a frame. Stucki's code does a loop for all frames, so all he needs to do really is to query the sprite object first.
-
ah now i see ... and now it works !!!
thank you gentleman ....
wouldnt it be easier to have an attribute for the delay of a complete sprite without having to set every single frames ?
-
Not really, the delay can be different for different animation frames. So using a simple loop in case you want to set the same delay doesn't seem like a big deal to me.
-
no it is not. you are right ..
i thought it as an additional attribute. but doing the loop is easy enough ..