Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: trying to change sprite delay but it doesnt work ..  (Read 4150 times)

0 Members and 1 Guest are viewing this topic.

Stucki

  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Posts: 325
  • I'm a llama!
    • View Profile
    • Schach-Welten
trying to change sprite delay but it doesnt work ..
« 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 ?

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: trying to change sprite delay but it doesnt work ..
« Reply #1 on: January 06, 2008, 11:34:53 PM »

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.





« Last Edit: January 06, 2008, 11:40:14 PM by metamorphium »
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: trying to change sprite delay but it doesnt work ..
« Reply #2 on: January 07, 2008, 07:39:32 AM »

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.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Stucki

  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Posts: 325
  • I'm a llama!
    • View Profile
    • Schach-Welten
Re: trying to change sprite delay but it doesnt work ..
« Reply #3 on: January 07, 2008, 10:16:50 AM »

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 ?

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: trying to change sprite delay but it doesnt work ..
« Reply #4 on: January 07, 2008, 11:32:25 AM »

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.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Stucki

  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Posts: 325
  • I'm a llama!
    • View Profile
    • Schach-Welten
Re: trying to change sprite delay but it doesnt work ..
« Reply #5 on: January 07, 2008, 11:35:53 AM »

no it is not. you are right ..
i thought it as an additional attribute. but doing the loop is easy enough ..
 

Page created in 0.017 seconds with 23 queries.