Creating a scrolling marquee

Blitz3D Forums/Blitz3D Programming/Creating a scrolling marquee

Jeremy Alessi(Posted 2003) [#1]
I'm trying to create a smooth scrolling message similar to Train Tracking. The problem is I begin printing at the right side of the screen of course and let the message scroll left, but I only want to display 100 characters at most since it slows down if you print the whole message every loop. The problem comes when the initial text goes off the left side of the screen and I crop it so that all the begining text is not printed and only 100 characters from the middle are printed.

The text starts getting jittery. I think the reason is because I'm using modulus to get a set point of where the text will be printed. So everytime the text moves left one full character I reset the text to be printed from 0 and then let it slowly move to being printed from -8 before reseting again. 8 is the width of one character on the FonTEXT virtual HUD. So evertime the total scroll distance mod 8 = 0 I reset my current scroll back to 0 and then decrement to -8 and print 100 characters.

Does anyone have a better method? I'm sure someone does since I've seen this sort of thing a few times before.


Sveinung(Posted 2003) [#2]
Pehaps this will work for you...

Graphics3D 640,480
SetBuffer BackBuffer()

scr_scroll=CreateImage(650,15)

tx$=tx$+"THIS IS A TEST..........................."
tx$=tx$+"And so on...................."

tx_pos=1
go=8

Repeat
Cls

go=go+2

If go>8 Then Gosub char
Gosub scroll

DrawImage scr_scroll,0,120

Flip
Until KeyHit(1)
End

.scroll
SetBuffer ImageBuffer(scr_scroll)
DrawBlock scr_scroll,-2,0
SetBuffer BackBuffer()
Return

.char
SetBuffer ImageBuffer(scr_scroll)
go=0
tmp$=Mid$(tx$,tx_pos,1)
Text 640,2,tmp$
tx_pos=tx_pos+1 : If tx_pos > Len(tx$) Then tx_pos=1
SetBuffer BackBuffer()
Return

at leats it works....

Sveinung


Rob Farley(Posted 2003) [#3]
A gift from me to you...

I just knocked this up so it's totally unoptimised.

Added to the code archives too

;smooth marquee by Rob Farley 2003 http://www.mentalillusion.co.uk

Graphics 640,480

message$="Example smooth horizonal scroller using text command, press esc to quit. This works with any size font, however, you may want to mask the edges either by scrolling the entire screen width or by adding a couple of blocks either side after the text command."

font=LoadFont("arial.ttf",30,True)
SetFont font




SetBuffer BackBuffer()

;width in pixels of the scroll (this is slightly bigger than the screen)
width=680

; create space padding for the beginning and end of message
padding$=""
Repeat
	padding=padding+" "
	Until StringWidth(padding)>=width

; add the padding to be beginning and end of message
message=padding+message+padding

; where you want to put the scroller (right over on the left so you don't get nasty bits at the edges)
xoffset=0
yoffset=240-(StringHeight("A")/2)



a=1

Color 255,255,255

Repeat

; find the next section of text to display
wid=1
Repeat
	If a+wid>Len(message$) Then a=1 ;loop back at end of message
	display$=Mid$(message$,a,wid)
	wid=wid+1
	Until StringWidth(display)>=width

; find the amount of scroll you need to move it
scroll=StringWidth(Mid$(message$,a,1))

; smoothly move the text
For n=0 To scroll-1
Cls
Text xoffset-n,yoffset,display
Flip
Next

;go to the next letter
a=a+1

Until KeyHit(1)