Looping Clouds BG

Started by madradubhcroga, Fri 27/04/2012 01:19:30

Previous topic - Next topic

madradubhcroga

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.


Hernald

#1
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.

madradubhcroga

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?

Khris

Move the SetTimer command inside the {} block that gets executed if the timer is expired.

madradubhcroga






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. 

madradubhcroga

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.

Khris

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.

madradubhcroga


SMF spam blocked by CleanTalk