Author Topic: Help with a Wait script for animated backgrounds  (Read 364 times)  Share 

Ok so i'm using SetBackgroundFrame to animate a background as i want to add a waiting period after the animation, the animation is a fish jumping in a pond but i don't want the fish to repeatedly jump in the animation.

This is the code i was trying but it stops the character from moving etc as its using Wait();

SetBackgroundFrame(0);
Wait(400);
SetBackgroundFrame(1);
Wait(5);
SetBackgroundFrame(2);
Wait(5);
SetBackgroundFrame(3);
Wait(5);

this code is being looped.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Help with a Wait script for animated backgrounds
« Reply #1 on: 09 May 2012, 17:35 »
For a small background animation you can use an object instead. Look up Object.Animate in the manual.

If you still want to do it using background frames:

Code: Adventure Game Studio
  1. // inside room_RepExec()
  2.  
  3.   if (IsTimerExpired(1)) {
  4.     nbf = (GetBackgroundFrame() + 1) % 4;
  5.     SetTimer(1, 400*(nbf==0) + 5*(nbf>0));
  6.     SetBackgroundFrame(nbf);
  7.   }

Final step: if it doesn't exist, add the after fadein event and in there, call SetTimer(1, 1); to start things off.
« Last Edit: 13 May 2012, 20:18 by Khris »
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Re: Help with a Wait script for animated backgrounds
« Reply #2 on: 10 May 2012, 12:24 »
For a small background animation you can use an object instead. Look up Object.Animate in the manual.

If you still want to do it using background frames:

[code]// inside room_RepExec()

  if (IsTimerExpired(1)) {
    nbf = (GetBackgroundFrame() + 1) % 4;
    SetTimer(1, 400*(nbf==0) + 5*(nbf>0));
    SetBackgroundFrame(nbf);
  }[/code]

Final step: if it doesn't exist, add the after fadein event and in there, call SetTimer(1, 1); to start things off.

Thanks for your help i got it to work using a timer with my original code :D

[code]function room_RepExec()

  if (IsTimerExpired(1)) {
    SetBackgroundFrame(1);
    Wait (5);
    SetBackgroundFrame(2);
    Wait (5);
    SetBackgroundFrame(3);
    Wait(5);
    SetBackgroundFrame(0);
    SetTimer(1, 200);
  }
}

function room_AfterFadeIn()
{
  SetBackgroundFrame(0);
  SetTimer(1, 200);
}[/code]

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Help with a Wait script for animated backgrounds
« Reply #3 on: 10 May 2012, 12:41 »
1. Don't quote the entire previous post. There's a reply button at the bottom.

2. No you didn't, because your game is blocked for 15 frames every 215 frames. And my code's shorter to boot. :)
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

geork

  • measure once, cut twice, say it was already broken
    • I can help with scripting
    •  
    • I can help with voice acting
    •  
Re: Help with a Wait script for animated backgrounds
« Reply #4 on: 10 May 2012, 14:34 »
It's important to get out of the habit of calling a Wait() command inside a function which is going to loop, as eventually the frame drop is noticeable. Khris' code is the best and most concise, but here is a layman's version (i.e. the version I would probabely make  :P) which tries to again not call Wait():
 [code]
int CurrentFrame;
function room_AfterFadeIn(){ 
   CurrentFrame = 0;
   SetBackgroundFrame(0); 
   SetTimer(1, 200);
}
function room_RepExec(){   
  if (IsTimerExpired(1)) {
    int MyValue = 5;
    CurrentFrame ++;   
    if (CurrentFrame == 4){ //As there frame numbers go up to 3, when it hits 4 we reset it to 0.
      CurrentFrame = 0;
      MyValue = 400; //Between Frame 0 and 1 you want a 400 frame interval, not 5
    }
    SetBackgroundFrame(CurrentFrame); 
    SetTimer(1, MyValue);
  }
}
[/code]

 This could will not block any frames! :-D
  So umm.....yeah...this might be easier than the other code to understand (i had trouble!), but certainly less efficient!