Code archives/Miscellaneous/Credits Scroller

This code has been declared by its author to be Public Domain code.

Download source code

Credits Scroller by Rob Farley2003
Okay this reads a text file and displays it in the form of a scroller like end credits of a movie.

It's pretty flexible as you can change font and colour and include images.

I've tried to comment all the bits I think need commenting. Give me a shout if it any bits of it don't make sense.

Copy and paste this below and save it as credits.txt and put it in the same folder as you save the code.
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552551This is a demonstration of the scroller
2552552551It's not really that impressive but it does the job
2552552551And I think it does it rather well!!
2552552551
0001002553What can you do with it?
2552552551
2552552552You can change font size
2550000002Font colour
2552552552And include images
2552552552
2552552552
9999999992c:\program files\blitz3d\tutorials\gcuk_tuts\b3dlogo_small.jpg
2552552552
2552552552
2552552552Very flexible little thing that runs from a text file
2552552552
2552550002It's so damn simple
2552550002You should be able to update it no problem to make it into
2552550002something a bit more special!!
2552552552
2552552552
2552552552If you do I'd love to see it!!
2552552552
2552552552
2552552552
2552552552
0002552551Oh one more thing... The text file format
0002552551
0002552551The first 10 characters of each line control the bits and pieces
0002552551This goes as follows:
0002552551RRRGGGBBBS
0002552551Where RRR is the red value ie 245, GGG and BBB are the same
0002552551S is the font which you code yourself
0002552551This could change both size and type face
0002552551On top of this if you set the RRRGGGBBB to 999999999 you can insert an image
0002552551And put any old number in the font character you then add the path
0002552551the image is automatically centred.
0002552551
0002552551
0002552551Anyway, take a look at the text file to get a better idea, it should all make sense!
0002552551
0002552551
2552552553Cheers, Rob.
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
2552552552
end
; Credits scroller
; 2003 Mental Illusion
; rob@mentalillusion.co.uk
; http://www.mentalillusion.co.uk

;---------------------------------------------------------------------------

; Text file format is rrrgggbbbx, where rrr is a 3 digit red value ie 054, ggg and bbb are for green and blue
; x is the font controller set up below.
; if you set 9999999991 this is for an image, the x value can be any legal font value you then follow this
; with the image path (see example below).

; This assumes you've got blitz3d installed in c:\program files if not change the line in the text file
; 9999999992c:\program files\blitz3d\tutorials\gcuk_tuts\b3dlogo_small.jpg
; to the correct path.

; hopefully this should be self explanitary


;set graphics mode
Graphics 640,480,32
SetBuffer BackBuffer()

; set up fonts
font1=LoadFont("Arial.TTF",11,True,False,False)
font2=LoadFont("Arial.TTF",21,False,False,False)
font3=LoadFont("Times.TTF",31,False,True,False)


; count the lines in the file
lines=0
filein = ReadFile("credits.txt")
Repeat
temp$=ReadLine$(filein)
lines=lines+1
Until temp$="end"
CloseFile( filein )


; set up arrays for holding text, images, and colours
Dim textlines$(lines)
Dim textcolour(lines,3)
Dim textsize(lines)
Dim images(lines)


; open up the file again and read it all in
filein = ReadFile("credits.txt")
For n=1 To lines
	temp$=ReadLine$(filein)
	textcolour(n,1)=Int(Left$(temp$,3))
	textcolour(n,2)=Int(Mid$(temp$,4,3))
	textcolour(n,3)=Int(Mid$(temp$,7,3))
	textsize(n)=Mid$(temp$,10,1)
	textlines$(n)=Mid$(temp$,11,Len(temp$)-10)
	If textcolour(n,1)+textcolour(n,2)+textcolour(n,3)=2997 Then images(n)=LoadImage(textlines$(n)) ;check for an image
	Next
CloseFile( filein )

;---------------------------------------------------------------------------


; Run the scroller
Gosub scroller



End

;---------------------------------------------------------------------------

.scroller

voffset=60
rows_displayed=20

;voffset will set how far off the top of the screen it will roll, with bigger fonts/images this needs to be higher
;if you have it too high you will lose rows off the bottom and you will therefore need to change the rows displayed
;on top of this you have to put blank padding at the beginning and end of the text file to make it seamless

For l=1 To lines-rows_displayed

For move=1 To 30 ; The lines are 30 pixels apart


Cls

; you'll see a lot of 640s and 320s here, this is because it's hard coded for 640x480, but you can change this
; the problem you'll encounter is as the screen y size increases you need to add more rows displayed

; draw the background
For n=0 To 240
	Color 0,0,n
	Rect 0,2*n,640,2,True
	Next

; draw the text/images
For n=0 To rows_displayed

	Color textcolour(n+l,1),textcolour(n+l,2),textcolour(n+l,3)
	If textsize(n+l)=1 SetFont font1
	If textsize(n+l)=2 SetFont font2
	If textsize(n+l)=3 SetFont font3

	If textcolour(n+l,1)+textcolour(n+l,2)+textcolour(n+l,3)<2997
		Text 320,(n*30)-move-voffset,textlines$(n+l),True,True
		Else
		DrawImage images(n+l),320-(ImageWidth(images(n+l))/2),(n*30)-move-voffset-(ImageHeight(images(n+l))/2)
		EndIf
	Next

If KeyDown(1) Return ;quit out

; wait for vblank and flip the screen
VWait
Flip
Delay 20
Next
Next
Return

Comments

Chad2004
Very nice :-)

Thanks


Rob Farley2004
It's odd seeing old old code being dredged up! That's horrible! I might have to re-do it nicer!


Code Archives Forum