View Full Version : Display text one line at a time?
mystica
08-18-2009, 11:02 PM
Hey, anyone know how to go about displaying a body of text, one line at a time?
I want to display lyrics to a Midnight Oil song, but want to reveal them one line at a time.
ShadowUK recently showed how to animate text in a paragraph-object
ie.
local Text = [[Hey look this is animated and this example is awesome.]];
for Position = 1, String.Length(Text) do
Paragraph.SetText("Paragraph1", string.sub(Text, 0, Position));
Application.Sleep(10);
end
... but I'm looking for a way to reveal text a whole line at a time with, say a 2 second gap between lines, rather than having individual letters race across the screen like it does with Shadow's code.
Because I'm looking to display lyrics to a song in this fashion, I don't really want to have to create a seperate paragraph-object for each line (of which there are 23 in total) ... so using a timer to delay the appearance of 23 paragraph-objects would be a pain in the butt.
So, does anyone know of a cool workaround for this?
Centauri Soldier
08-19-2009, 02:51 AM
If you are reading these lyrics from a file. You would read the file to a table.
If you want to hard code the lyrics then code each line into an indexed table.
There are several ways to put the lyrics into a table, however you want to do it, just make sure that each line gets into a table. (for my example, I hard-coded them);
Although, you could modify this to use a delimited string instead of a table.
I made this dynamic assuming that you will be doing this for more than one song.
First, create a paragraph object called "par lyrics output".
Next, insert this code into your application.
On Preload
tLyrics = {};
tLyrics["Beds are Burning"] = {};
tLyrics["Beds are Burning"][1] = "Out where the river broke";
tLyrics["Beds are Burning"][2] = "The blood wood and the desert oak";
tLyrics["Beds are Burning"][3] = "Holden wrecks and boiling diesels";
tLyrics["Beds are Burning"][4] = "Steam in forty five degrees";
tLyrics["Beds are Burning"][5] = "";
tLyrics["Beds are Burning"][6] = "The time has come";
tLyrics["Beds are Burning"][7] = "To say fair's fair";
tLyrics["Beds are Burning"][8] = "To pay the rent";
tLyrics["Beds are Burning"][9] = "To pay our share";
tLyrics["Beds are Burning"][10] = "";
tLyrics["Beds are Burning"][11] = "The time has come";
tLyrics["Beds are Burning"][12] = "A fact's a fact";
tLyrics["Beds are Burning"][13] = "It belongs to them";
tLyrics["Beds are Burning"][14] = "Let's give it back";
tLyrics["Beds are Burning"][15] = "";
tLyrics["Beds are Burning"][16] = "How can we dance when our earth is turning?";
tLyrics["Beds are Burning"][17] = "How do we sleep while our beds are burning?";
tLyrics["Beds are Burning"][18] = "How can we dance when our earth is turning?";
tLyrics["Beds are Burning"][19] = "How do we sleep while our beds are burning?";
tLyrics["Beds are Burning"][20] = "";
tLyrics["Beds are Burning"][21] = "The time has come";
tLyrics["Beds are Burning"][22] = "To say fair's fair";
tLyrics["Beds are Burning"][23] = "To pay the rent, now";
tLyrics["Beds are Burning"][24] = "To pay our share";
tLyrics["Beds are Burning"][25] = "";
tLyrics["Beds are Burning"][26] = "Four wheels scare the cockatoos";
tLyrics["Beds are Burning"][27] = "From Kintore East to Yuendemu";
tLyrics["Beds are Burning"][28] = "The western desert lives and breathes";
tLyrics["Beds are Burning"][29] = "In forty five degrees";
tLyrics["Beds are Burning"][30] = "";
tLyrics["Beds are Burning"][31] = "The time has come";
tLyrics["Beds are Burning"][32] = "To say fair's fair";
tLyrics["Beds are Burning"][33] = "To pay the rent";
tLyrics["Beds are Burning"][34] = "To pay our share";
tLyrics["Beds are Burning"][35] = "";
tLyrics["Beds are Burning"][36] = "The time has come";
tLyrics["Beds are Burning"][37] = "A fact's a fact";
tLyrics["Beds are Burning"][38] = "It belongs to them";
tLyrics["Beds are Burning"][39] = "Let's give it back";
tLyrics["Beds are Burning"][40] = "";
tLyrics["Beds are Burning"][41] = "How can we dance when our earth is turning?";
tLyrics["Beds are Burning"][42] = "How do we sleep while our beds are burning?";
tLyrics["Beds are Burning"][43] = "How can we dance when our earth is turning?";
tLyrics["Beds are Burning"][44] = "How do we sleep while our beds are burning?";
tLyrics["Beds are Burning"][45] = "";
tLyrics["Beds are Burning"][46] = "The time has come";
tLyrics["Beds are Burning"][47] = "To say fair's fair";
tLyrics["Beds are Burning"][48] = "To pay the rent, now";
tLyrics["Beds are Burning"][49] = "To pay our share";
tLyrics["Beds are Burning"][50] = "";
tLyrics["Beds are Burning"][51] = "The time has come";
tLyrics["Beds are Burning"][52] = "A fact's a fact";
tLyrics["Beds are Burning"][53] = "It belongs to them";
tLyrics["Beds are Burning"][54] = "We're gonna give it back";
tLyrics["Beds are Burning"][55] = "";
tLyrics["Beds are Burning"][56] = "How can we dance when our earth is turning?";
tLyrics["Beds are Burning"][57] = "How do we sleep while our beds are burning?";
tCurrentLine = {};
tCurrentLine["Beds are Burning"] = 0;
On a Trigger (a Button or the like)
Page.StartTimer(650);
sActiveSong = "Beds are Burning";
On Timer
local nCurrentLine = tCurrentLine[sActiveSong] + 1;
if nCurrentLine ~= Table.Count(tLyrics[sActiveSong]) + 1 then
if nCurrentLine == 1 then
Paragraph.SetText("par lyrics output", "");
end
tCurrentLine[sActiveSong] = nCurrentLine;
Paragraph.SetText("par lyrics output", Paragraph.GetText("par lyrics output").."\r\n"..tLyrics[sActiveSong][tCurrentLine[sActiveSong]]);
Paragraph.SetScrollPos("par lyrics output", Paragraph.GetScrollRange("par lyrics output", true).Max, true);
else
tCurrentLine[sActiveSong] = 0;
Page.StopTimer();
end
Is that what you're after?
And yes, happiness is a warm gun...:D
mystica
08-19-2009, 03:47 AM
Ah thanx, man ... that's exactly what I'm looking for ... sweet!
PS.
I'll be using this for "Forgotten Years" ... it's part of a multimedia-project for high-school kids studying History (Australia in the Interwar Period). So when they ask (and I know they will) ... I'll be sure to tell 'em the code came from a guy called Centauri Soldier ... they'll dig that! :cool
MicroByte
08-19-2009, 04:24 AM
why not just use a lyric tag?
mystica
08-19-2009, 04:44 AM
why not just use a lyric tag?
How does this work with an AMS project? Maybe an example? (Are we talking XML or something?)
Not sure how you mean. :huh
mystica
08-19-2009, 06:19 AM
Okay Microbyte, I've made this lyric-tag (also attached below):
[ar:Midnight Oil]
[ti:Forgotten Years]
[00:21]Few of the sins of the father
[00:24]Are visited upon the son
[00:28]Hearts have been hard
[00:31]Hands have been clenched into fists too long
[00:34]Our sons need never be soldiers
[00:37]Our daughters will never need guns
[00:40]These are the years between
[00:43]These are the years that were hard fought and won
[00:46]Contracts torn at the edges
[00:49]Old signatures stained with tears
[00:53]Seasons of war and grace
[00:56]These should not be forgotten years
[00:59]Still it aches like tetanus
[01:02]It reeks of politics
[01:06]How many dreams remain?
[01:09]This is a feeling too strong to contain
[01:12]The hardest years, the darkest years
[01:15]The roarin' years, the fallen years
[01:21]These should not be forgotten years
[01:24]The hardest years, the wildest years
[01:27]The desperate and divided years
[01:33]We will remember
[01:35]These should not be forgotten years
[01:43]Our shoreline was never invaded
[01:46]Our country was never in flames
[01:49]This is the calm we breathe
[01:53]This is a feeling too strong to contain
[01:56]Still it aches like tetanus
[01:59]It reeks of politics
[01:02]Signatures stained with tears
[01:06]Who can remember, we've got to remember
[02:09]The hardest years, the darkest years
[02:12]The roarin' years, the fallen years
[02:18]These should not be forgotten years
[02:21]The hardest years, the wildest years
[02:24]The desperate and divided years
[02:30]We will remember
[02:32]These should not be forgotten years
[03:02]The hardest years, the darkest years
[03:05]The roarin' years, the fallen years
[03:11]These should not be forgotten years
[03:14]The hardest years, the wildest years
[03:17]The desperate and divided years
[03:23]We will remember
[03:25]These should not be forgotten years
[03:27]Forsaking aching breaking years
[03:30]The time 'n' tested heartbreak years
[03:36]These should not be forgotten years
[03:39]The blinded years, the binded years
[03:42]The desperate and divided years
[03:48]These should not be forgotten years
[03:54]Remember...
... and saved it as an .lrc file, but how do I use it with AMS? I'm assuming I've got to link it with the Media-Object, yeh? But how? :huh
Centauri Soldier
08-19-2009, 12:26 PM
Probably by getting the current play time in the song every second. Then check to see if it matches any tables entries in your lrc file. That's a pretty neat idea.
mystica
08-19-2009, 10:33 PM
Probably by getting the current play time in the song every second. Then check to see if it matches any tables entries in your lrc file. That's a pretty neat idea.
Um ... huh? :huh
mystica
08-20-2009, 01:30 AM
Probably by getting the current play time in the song every second. Then check to see if it matches any tables entries in your lrc file. That's a pretty neat idea.
Okay ... so you mean something along these lines, yeh?
strLrc = TextFile.ReadToString("AutoPlay\\Docs\\MIDNIGHT OIL Forgotten Years.lrc");
result = Audio.GetCurrentPos(CHANNEL_USER1);
if result == "21:00" then
Paragraph.SetText("Paragraph1", strLrc);
end
... but for it to grab each line at the appropriate moment, wouldn't I need to express the .lrc-file as a table ... in which case, aren't we right back where we started with your original suggestion of having an indexed table?
Stefan_M
08-20-2009, 11:12 PM
Another way:
1. Get time from the aktual line
2. Get time from the next line
3. Show aktual line
4. Wait time difference
5. next with line 1
mystica
08-21-2009, 02:09 AM
you know ... I think I'll just stick with Centauri's original code, it works! Not going to bang my head against the wall with this one, unless i have some kind of epiphany on how to use the .lrc file with less code.
Powered by vBulletin™ Version 4.0.5 Copyright © 2010 vBulletin Solutions, Inc. All rights reserved.