Here's a better example. I made these functions ages ago. You need to play about with the 'Tolerance' value to get some sentences type out properly. You could probably find a word wraping function to do it better tho :)
Graphics 640,480,0,2
SetBuffer BackBuffer()
Type Letter
Field Letter$,Xpos,Ypos,Time#,Sound
End Type
;--------------;
; Type Letters ;----------------------------------------------------------
;--------------;
Function TypeText (Xpos=0,Ypos=0,MaxX=100,MaxY=100,Texts$="",Space=10,Height=12,Time=5,Tolerance=10,Sound=0)
Local LR.Letter,A,L
For A = 1 To Len (Texts)
LR.Letter = New Letter
LR\Letter = Mid (Texts,A,1)
LR\Xpos = Xpos + (L*Space)
LR\Ypos = Ypos
LR\Time = A*Time
LR\Sound = Sound
L = L + 1
If LR\Letter = Chr (13) Or LR\Letter = Chr (10)
LR\Xpos = Xpos
LR\Ypos = Ypos + Height
LR\Letter = " "
Ypos = Ypos + Height
L = 1
EndIf
If LR\Xpos >= (MaxX-Tolerance)
If LR\Letter = " "
LR\Xpos = Xpos
LR\Ypos = Ypos + Height
Ypos = Ypos + Height
L = 1
EndIf
EndIf
If LR\Xpos >= MaxX
LR\Xpos = Xpos
LR\Ypos = Ypos + Height
Ypos = Ypos + Height
L = 1
EndIf
If LR\Xpos = Xpos
If LR\Letter = " "
Delete LR
L = 0
EndIf
EndIf
Next
End Function
;------------------;
; Draw all Letters ;------------------------------------------------------
;------------------;
Function DrawLetters()
Local LR.Letter
For LR.Letter = Each Letter
LR\Time = LR\Time - 1
If LR\Time = 0 And LR\Sound <> 0
PlaySound LR\Sound
EndIf
If LR\Time <= 0
Text LR\Xpos,LR\Ypos,LR\Letter
EndIf
Next
End Function
;--------------------;
; Remove all Letters ;----------------------------------------------------
;--------------------;
Function DeleteLetters()
Local LR.Letter
For LR.Letter = Each Letter
Delete LR
Next
End Function
;---------;
; Example ;---------------------------------------------------------------
;---------;
; Text from Wikipedia :)
;
; Xpos = Xpos of text start
; Ypos = Ypos of text start
; MaxX = Width of text box
; MaxY = Height of text box
; Texts = Text to type
; Space = Space between letters
; Height = Height of each line
; Time = Delay between letters
; Tolerance = Max word size from end of line (?)
; Sound = Sound to play for each letter
Local Txt$ = "The Waterboys are a band formed in 1983 by Mike Scott. The band's membership, past and present, has been composed mainly of musicians from Scotland and Ireland. London, Dublin, Spiddal, New York and Findhorn have all served as a home for the group."+Chr(13)+Chr(13)+"The band has played in a number of different styles, but most often their music can be described as a mix of Celtic folk music with rock and roll, or folk rock. After ten years of recording and touring, the band dissolved in 1993 and Scott pursued a solo career."+Chr(13)+Chr(13)+"The band reformed in 2000, and continues to release albums and tour worldwide. The early Waterboys sound was dubbed `The Big Music' after a song on their second album, A Pagan Place. This musical style was described by Scott as `a metaphor For seeing God's signature in the world'. Their songs, largely written by Scott, often contain literary references And are frequently concerned with spirituality."+Chr(13)+Chr(13)+"Both the group and its members' solo careers have received much praise from both rock and folk music critics, but The Waterboys as a band has never received the commercial success that some of its members have had independently."
TypeText (20,20,600,440,Txt,10,12,5,50,0)
While Not KeyDown (1)
Cls
DrawLetters()
Flip
Wend
DeleteLetters()
End
Hope it helps :)