Automatic Scrolling from right to left

Started by HillBilly, Thu 20/05/2004 11:26:09

Previous topic - Next topic

HillBilly

Okay, I've been using a few hours last night, and around 2 today, to figure this out. I've been searching in the forum, the manual, websites and checking other games. Unfortantly, none of them seem to solve my problem:

I want the background(640x200) to scroll from the right side to the left. Whitout the character(I've hidden him), while it displays text in the centre. I also need it to scroll slow.

Is there any way to solve this?

Thanks!  :)

ilSilente

Look for function "SetViewport" in the manual.

HillBilly

That's what I've been using:

Code: ags
int xpos = 0;
while (xpos < 300) {
  SetViewport(0, xpos);
  Wait(1);
  xpos++;
}

ilSilente

#3
Here a working example:

Code: ags

function my_cutscene() {

StartCutscene(5);

int overlay, xpos = 0;
while (xpos < 60) {
Ã,  // Display text. I used overlays since they aren't blocking and they don't move while scrolling the sceen
Ã,  if (xpos==0) overlay = CreateTextOverlay (0,80,650,1,15,"This is a text overlay");
Ã,  if (xpos==30) {
Ã,  Ã,  RemoveOverlay(overlay); // Delete previous message
Ã,  Ã,  overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
Ã,  }
Ã,  // ..
Ã,  SetViewport(xpos, 0);
Ã,  Wait(5);
Ã,  xpos++;
}
ReleaseViewport(); // Returns the viewport as it was before the cutscene - maybe non necessary in your game
RemoveOverlay(overlay); // Remove the last message

EndCutscene();

}


PS: CreateTextOverlay does NOT center the text in the specified area! [EDIT]You can use function GetTextWidth to center strings[/EDIT]

Ok, this is working but just an idea.

HillBilly

Thanks! But how do I make it go the other way(It's currently left-right)?

ilSilente

I'm back! Let's see... SetViewport accept coordinates in 320x200-scale. Since your background is 640x200 I suppose you are designing a 320x200 game.
So you need to scroll 320 pixel from right to left. This means your viewport is initially set at coord (320, 0).

here the modified script (only lines marked with '*' have been changed), I didn't test this but it should work fine:

Code: ags

function my_cutscene() {

StartCutscene(5);

* int overlay, xpos = 320;
* SetViewPort(xpos, 0);
* while (xpos > 0) {
Ã,  // Display text. I used overlays since they aren't blocking and they don't move while scrolling the sceen
Ã,  if (xpos==320) overlay = CreateTextOverlay (0,80,650,1,15,"This is a text overlay");
Ã,  if (xpos==290) {
Ã,  Ã,  RemoveOverlay(overlay); // Delete previous message
Ã,  Ã,  overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
Ã,  }
Ã,  // ..
Ã,  SetViewport(xpos, 0);
Ã,  Wait(5);
*Ã,  xpos--;
}
ReleaseViewport(); // Returns the viewport as it was before the cutscene - maybe non necessary in your game
RemoveOverlay(overlay); // Remove the last message

EndCutscene();

}


Note that the sequence of "if (xpos==???)" uses now numbers in inverted order.

HillBilly

Okay, the move-from-right-to-left thing worked perfect now, but the text didn't show up. I had to remove the SetViewPort(xpos, 0); because it was an "undefined token".

Code: ags
  // script for room: Player enters screen (after fadein)
int overlay, xpos = 320;
SetViewPort(xpos, 0); //REMOVED!
while (xpos > 0) {
  // Display text. I used overlays since they aren't blocking and they don't move while scrolling the sceen
  if (xpos==0) overlay = CreateTextOverlay (0,80,650,1,15,"This is a text overlay");
  if (xpos==30) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
  }
  // ..
  SetViewport(xpos, 0);
  Wait(5);
  xpos--;
}
ReleaseViewport(); // Returns the viewport as it was before the cutscene - maybe non necessary in your game
RemoveOverlay(overlay); // Remove the last message

ilSilente

Yes.

Code: ags
SetViewPort(xpos, 0); //REMOVED!

The right spelling is "SetViewport(xpos, 0);" However this instruction is not very important.

Text didn't show up because you need to change the block of if statements. Look at Reply #7:

Code: ags
if (xpos==320) ...etc etc...
  if (xpos==290) ...etc etc...


I didn't marked these lines but i told you: "Note that the sequence of "if (xpos==???)" uses now numbers in inverted order. " ;) Got it?

HillBilly

Like this?

Code: ags
  // script for room: Player enters screen (after fadein)
int overlay, xpos = 320;
SetViewport(xpos, 0);
while (xpos > 0) {
  // Display text. I used overlays since they aren't blocking and they don't move while scrolling the sceen
  if (xpos==320) overlay = CreateTextOverlay (0,80,650,1,15,"This is a text overlay");
  if (xpos==290) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
  // ..
  SetViewport(xpos, 0);
  Wait(5);
  xpos--;
}
}
ReleaseViewport(); // Returns the viewport as it was before the cutscene - maybe non necessary in your game
RemoveOverlay(overlay); // Remove the last message


Now it says I'm recreating too many overlays.  ???

ilSilente

#9
QuoteNow it says I'm recreating too many overlays.Ã,  ???

What? ??? Did you use RemoveOverlay(overlay) before any CreatetextOverlay?
AGS supports max 10 overlays but using CreateTextOverlay and RemoveOverlay in sequence you use only 1 overlay at time.

--EDIT--

Ahah... wait... wait!
Messages should be created using this sintax:

Code: ags

  if (xpos==320) overlay = CreateTextOverlay (0,80,650,1,15,"This is a text overlay");
  if (xpos==290) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
  }
  if (xpos==250) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
  }
  if (xpos==200) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
  }


Maybe you used:

Code: ags

  if (xpos==320) overlay = CreateTextOverlay (0,80,650,1,15,"This is a text overlay");
  if (xpos==290) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
  }
  if (xpos==250) overlay = CreateTextOverlay (0,80,650,1,15,"This is a text overlay");
  if (xpos==220) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
  }
  if (xpos==200) overlay = CreateTextOverlay (0,80,650,1,15,"This is a text overlay");
  if (xpos==180) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay");
  }


And yes, this is wrong (and really slows down the AGS engine)

HillBilly

Thanks, it works perfect now! I must remember to put you on the "thanks to" list.  ;)

And if it helps anyone else, here's the working code:

Code: ags
  // script for room: Player enters screen (after fadein)
int overlay, xpos = 320;
SetViewport(xpos, 0);
while (xpos > 0) {
  // Display text. I used overlays since they aren't blocking and they don't move while scrolling the sceen
  if (xpos==320) overlay = CreateTextOverlay (0,80,650,1,15,"This is a text overlay");
  if (xpos==290) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay1");
  }
  if (xpos==250) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay2");
  }
  if (xpos==200) {
    RemoveOverlay(overlay); // Delete previous message
    overlay = CreateTextOverlay (0,80,650,1,15,"This is another text overlay3");
  }
  SetViewport(xpos, 0);
  Wait(5);
  xpos--;
}

SMF spam blocked by CleanTalk