Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: madradubhcroga on Fri 27/04/2012 01:19:30

Title: Looping Clouds BG
Post by: madradubhcroga on Fri 27/04/2012 01:19:30
Hello.

My game starts with a (playable) dream sequence:

Player has wings and is flying across the sky collecting coins.
I want clouds to scroll from right to left to suggest the player's left to right motion.
I've imported 3 clouds as characters.
Here's what I've written:


function room_AfterFadeIn()
{
cCloud1.Walk(-160, 372, eNoBlock, eAnywhere);
cCloud2.Walk(-260, 448, eNoBlock, eAnywhere);
cCloud3.Walk(-160, 581, eNoBlock, eAnywhere);


   
 
}

function room_RepExec()
{
SetTimer(1, 1200);
if (IsTimerExpired(1)){
  cCloud1.ChangeRoom(2, 914, 372);
    cCloud1.Walk(-200, 372, eNoBlock, eAnywhere);
    cCloud2.ChangeRoom(2, 1314, 448);
   cCloud2.Walk(-260, 448, eNoBlock, eAnywhere);
   cCloud2.ChangeRoom(2, 908, 581);
cCloud3.Walk(-160, 581, eNoBlock, eAnywhere);
SetTimer(1, 1200);


Can anybody tell me what I've done wrong? 

Thanks.

Title: Re: Looping Clouds BG
Post by: Hernald on Fri 27/04/2012 01:37:14
You've set the timer just before you check if it's expired; doing it that way, it never will.
Take the first SetTimer out of the RepExec loop and put it in the AfterFadeIn or somewhere like that.

Also close the if statement with a final curly bracket. And the RepExec function as well.
Title: Re: Looping Clouds BG
Post by: madradubhcroga on Fri 27/04/2012 01:51:07
Thank you Hernald!

Ok, it's getting there.

I put the setTimer under  function room_AfterFadeIn()

and the clouds scroll again once the timer is expired.


But if it's not under function room_RepExec()
it only happens once and then the clouds are gone.
How do I make it repeat for the duration of the scene?
Title: Re: Looping Clouds BG
Post by: Khris on Fri 27/04/2012 02:02:56
Move the SetTimer command inside the {} block that gets executed if the timer is expired.
Title: Re: Looping Clouds BG
Post by: madradubhcroga on Fri 27/04/2012 02:25:17





Like this?

function room_Load()
{


if (IsTimerExpired(1)){
  cCloud1.ChangeRoom(2, 914, 372);
    cCloud1.Walk(-200, 372, eNoBlock, eAnywhere);
    cCloud2.ChangeRoom(2, 1314, 448);
   cCloud2.Walk(-260, 448, eNoBlock, eAnywhere);
   cCloud2.ChangeRoom(2, 908, 581);
cCloud3.Walk(-160, 581, eNoBlock, eAnywhere);

SetTimer(1, 120);
}


    }

Sorry.  Thank you for helping me; I'm still not getting it. 
Title: Re: Looping Clouds BG
Post by: madradubhcroga on Fri 27/04/2012 06:20:51
Ah!

It works when I put setTimer at the end of the RepExec section and room_Load.

function room_Load()
{

SetTimer(1, 800);


    }

function room_RepExec()
{
if (IsTimerExpired(1)){
  cCloud1.ChangeRoom(2, 914, 372);
    cCloud1.Walk(-200, 372, eNoBlock, eAnywhere);
    cCloud2.ChangeRoom(2, 1314, 448);
   cCloud2.Walk(-260, 448, eNoBlock, eAnywhere);
   cCloud2.ChangeRoom(2, 908, 581);
cCloud3.Walk(-160, 581, eNoBlock, eAnywhere);
SetTimer(1, 800);}
}

Much obliged.
Title: Re: Looping Clouds BG
Post by: Khris on Fri 27/04/2012 14:34:57
Sorry, I could've been clearer. When I said "move" the command, I was referring to the one at the start of your rep_ex because I hadn't seen the second one which already was where it belonged.

For reference: one SetTimer command in room_Load/AfterFadein to start things off, then another inside if IsTimerExpired() { ... } to keep things going.
Title: Re: Looping Clouds BG
Post by: madradubhcroga on Sat 28/04/2012 00:05:15


Nice one.

Thank you!