Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HillBilly on Thu 20/05/2004 11:26:09

Title: Automatic Scrolling from right to left
Post by: HillBilly on Thu 20/05/2004 11:26:09
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!  :)
Title: Re: Automatic Scrolling from right to left
Post by: ilSilente on Thu 20/05/2004 11:59:07
Look for function "SetViewport" in the manual.
Title: Re: Automatic Scrolling from right to left
Post by: HillBilly on Thu 20/05/2004 12:17:46
That's what I've been using:

int xpos = 0;
while (xpos < 300) {
  SetViewport(0, xpos);
  Wait(1);
  xpos++;
}
Title: Re: Automatic Scrolling from right to left
Post by: ilSilente on Thu 20/05/2004 12:30:04
Here a working example:


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.
Title: Re: Automatic Scrolling from right to left
Post by: HillBilly on Thu 20/05/2004 12:41:46
Thanks! But how do I make it go the other way(It's currently left-right)?
Title: Re: Automatic Scrolling from right to left
Post by: ilSilente on Thu 20/05/2004 13:22:15
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:


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.
Title: Re: Automatic Scrolling from right to left
Post by: HillBilly on Thu 20/05/2004 13:40:18
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".

  // 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
Title: Re: Automatic Scrolling from right to left
Post by: ilSilente on Thu 20/05/2004 13:54:35
Yes.

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:

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?
Title: Re: Automatic Scrolling from right to left
Post by: HillBilly on Thu 20/05/2004 14:10:07
Like this?

  // 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.  ???
Title: Re: Automatic Scrolling from right to left
Post by: ilSilente on Thu 20/05/2004 14:22:18
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:


  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:


  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)
Title: Re: Automatic Scrolling from right to left
Post by: HillBilly on Thu 20/05/2004 14:38:06
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:

  // 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--;
}