Overlay for credits issue

Started by markbilly, Sun 12/06/2011 14:54:30

Previous topic - Next topic

markbilly

I have written, with the help of a few threads on the forum, a function for typewriter-style credits.

Unfortunately, when I re-use the function for the next line of the credits, the line before disappears because I've written over it.

I tried having the Overlay* credit as an argument of the function, so a new Overlay is created each time a use it. This didn't work though, for some reason, and it was also really messy. I was declaring an Overlay for each line of the credits and exporting/importing them all. Eurgh!

Here is the code for the function and then how it's use in the room script. Any ideas how I can tell it to make a new Overlay for each use of the function and have it stick around so the credits don't disappear.

Code: ags

function CreditsMessage(String message, int y_coord)
{
  Overlay* credit;
  int cred_colour = (Random(51000) + 9000);
  int i = 1;
  while (i < message.Length) { 
    String cred_part = message.Truncate(i);
    credit = Overlay.CreateTextual(10, y_coord, 300, Game.SpeechFont, cred_colour, cred_part);
    Wait(2);
    i++;
  }
  credit = Overlay.CreateTextual(10, y_coord, 300, Game.SpeechFont, cred_colour, message);
  Wait(20);
}


Code: ags

  CreditsMessage("XXXX",50);
  CreditsMessage("XXXX",55);
  Wait(20);
  CreditsMessage("XXXX",65);
  CreditsMessage("XXXX",70);
  Wait(20);
  CreditsMessage("XXXX",75);
  CreditsMessage("XXXX",80);
  Wait(20);
  CreditsMessage("XXXX",85);
  CreditsMessage("XXXX",90);
  Wait(20);
  CreditsMessage("XXXX",95);
  CreditsMessage("XXXX",100);
  CreditsMessage("XXXX",105);
  CreditsMessage("XXXX",110);
  CreditsMessage("XXXX",115);
  Wait(120);
  RestartGame();


Thanks (again!)
Mark
 

Khris

Try this:

Code: ags
Overlay*credits[20];
int credit_index;

function CreditsMessage(String message, int y_coord)
{
  Overlay* credit;
  int cred_colour = (Random(51000) + 9000);
  int i = 1;
  while (i < message.Length) { 
    String cred_part = message.Truncate(i);
    credit = Overlay.CreateTextual(10, y_coord, 300, Game.SpeechFont, cred_colour, cred_part);
    Wait(2);
    i++;
  }
  credit.Remove();
  credits[credit_index] = Overlay.CreateTextual(10, y_coord, 300, Game.SpeechFont, cred_colour, message);
  credit_index++;
  if (credit_index == 20) credit_index = 0;
  Wait(20);
}

markbilly

Works a treat. Thanks, Khris!
 

SMF spam blocked by CleanTalk