Scrolling text? (

Blitz3D Forums/Blitz3D Programming/Scrolling text? (

Cubed Inc.(Posted 2012) [#1]
Hey guys. I was wondering how you can create scrolling text, where the letters show up one by one rather than all at once so it is easier to read. It's seen in literally every RPG ever made (I can't even name one where it doesn't show up in)

Again, any help is greatly appreciated.


Kryzon(Posted 2012) [#2]
It usually works this way: you have a string you want to draw on the screen which represents the entire text content of the text-box.

So instead of rendering all that text at once like you'd usually do, you time it so that at every timer tick (= every time the delay time for the timer passes) you advance by '1' the total amount of displayed characters of that entire text.
At every timer tick you're increasing the number of characters of that message to display.
You don't hide the old characters, you keep drawing them to the screen - the difference is that at every timer tick you have a new character to be drawn.

This gives the effect of the message being progressively written.

So you basically need three elements:

- the message to be displayed (a huge 'string' value);
- the graphic symbols for the font characters (be them 2D images, pixel-perfect sprites, actual Blitz3D Text() etc.);
- timer logic and a counter variable to advance the total amount of characters of the message being displayed.


Amanda Dearheart(Posted 2012) [#3]
Hi there,

I have no idea if this is what you mean, but try out this piece of code.
BTW, the sound statement in this code doesn't work properly!

AppTitle ("Typed Text")

Global Snd1
Global Snd2
Global switch = 1

Sounds()

Graphics 800,600,32,1
TypeText(10, 10, "Hi there")
TypeText(10, 25, "this is Lola")
TypeText(10, 40, "I have something important to tell you")

WaitKey()
End

Function Sounds()
	
	Snd1 = LoadSound("Project Raven/example/tutorial.base/data/sound/testing.wav")
	Snd2 = LoadSound("Project Raven/example/starter.fps/data/dialogs/sounds/test2.wav")
	
End Function

Function TypeText( x, y, Msg$ )
	
	For M = 1 to Len(Msg$) 
		Delay 100
		Text x + M * 10, y, Mid$(Msg$,M,1)
		switch = -switch
		if (switch = 1) then PlaySound( Snd1 ) else PlaySound( Snd2 )		 
	Next 
	
End Function


Last edited 2012


Amanda Dearheart(Posted 2012) [#4]
Hi there,

I have no idea if this is what you mean, but try out this piece of code.
BTW, the sound statement is this code doesn't work properly!

AppTitle ("Typed Text")

Global Snd1
Global Snd2
Global switch = 1

Sounds()

Graphics 800,600,32,1
TypeText(10, 10, "Hi there")
TypeText(10, 25, "this is Lola")
TypeText(10, 40, "I have something important to tell you")

WaitKey()
End

Function Sounds()
	
	Snd1 = LoadSound("Project Raven/example/tutorial.base/data/sound/testing.wav")
	Snd2 = LoadSound("Project Raven/example/starter.fps/data/dialogs/sounds/test2.wav")
	
End Function

Function TypeText( x, y, Msg$ )
	
	For M = 1 to Len(Msg$) 
		Delay 100
		Text x + M * 10, y, Mid$(Msg$,M,1)
		switch = -switch
		if (switch = 1) then PlaySound( Snd1 ) else PlaySound( Snd2 )		 
	Next 
	
End Function


Last edited 2012


Addi(Posted 2012) [#5]
Try it like this:

Graphics 800, 600, 16, 2
SetBuffer BackBuffer()

Global s$ ="Hello"
Global counter = 1

Global timer = 100
Global fTimer = CreateTimer(60)

While Not KeyHit(1)

timer = timer-1
If timer=0 Then
timer = 100
If counter+1 <= Len(s$) Then counter = counter+1
End If

Text 400, 300, Left$(s$, counter), True, True

WaitTimer fTimer
Flip(0)
Cls
Wend

If you use Delay, your whole programm will be stopped for a certain time.


Rob the Great(Posted 2012) [#6]
If you're interested:
http://blitzbasic.com/codearcs/codearcs.php?code=2889
It's a complicated system, but it does some pretty cool things. The catch is that you need the FastImage library to run the code. If you don't have it, you can download a demo version to run my sample, or if you have the patience, you can look over my code and get an idea for how it works. It's essentially an expanded form of the examples above, just with a lot of extra functionality built into it.