credits vertical scrolling text

BlitzMax Forums/BlitzMax Programming/credits vertical scrolling text

Hi !
Just before re-invent the wheel, is there somewhere a code to display a classic vertical scrolling text (for credits) ?
Thanks !

Do a forums-wide search, there are a few bitmap font libraries out there. Personally, I use the one sswift gave me to go with his sprite library and it kicks gobs of ass.

SpaceAce

Here you go:
Type TElement

	Method add(myTElement:TElement) Abstract
	Method draw:Int(ypos:Int) Abstract

End Type

Type TLeaf Extends TElement
	Method add(myTElement:TElement)
		Throw "LeafAttachmentException"
	End Method
	
	Method draw:Int(ypos:Int) Abstract
End Type

Type TContainer Extends TElement
	Field myTList:TList
		
	Function create:TContainer()
		Local myTContainer:TContainer = New TContainer
		myTContainer.myTList = New TList
		Return myTContainer
	End Function

	Method add(myTElement:TElement)
		myTList.addLast(myTElement)
	End Method

	Method draw:Int(ypos:Int)
		For Local i:TElement = EachIn myTList
			ypos = i.draw(ypos)
		Next
		Return ypos
	End Method
End Type

Type TTextLeaf Extends TLeaf
	Field text:String

	Function create:TElement(myText:String)
		Local myTTextLeaf:TTextLeaf = New TTextLeaf
		myTTextLeaf.text = myText
		Return myTTextLeaf
	End Function

	Method draw:Int(ypos:Int)
		If ypos > 0 Or ypos < GraphicsHeight()
			DrawText text,0,ypos
		EndIf
		ypos:+TextHeight(text)
		Return ypos
	End Method
End Type

Type TImageLeaf Extends TLeaf
	Field image:TImage

	Function create:TElement(myImage:TImage)
		Local myTImageLeaf:TImageLeaf = New TImageLeaf
		myTImageLeaf.image = myImage
		Return myTImageLeaf
	End Function


	Method draw:Int(ypos:Int)
		If ypos > 0 Or ypos < GraphicsHeight()
			DrawImage image,0,ypos
		EndIf
		ypos:+ImageHeight(image)
		Return ypos
	End Method
End Type

Graphics 800,600

Local overlay:TImage = LoadImage("incbin::../shared resources/overlay.png")
Local myRoot:TElement = TContainer.create()
myRoot.add(TTextLeaf.create("!!! HadokeN !!!"))
myRoot.add(TTextLeaf.create("!!! HadokeN !!!"))
myRoot.add(TTextLeaf.create("!!! HadokeN !!!"))
myRoot.add(TTextLeaf.create("!!! HadokeN !!!"))
myRoot.add(TImageLeaf.create(LoadImage("incbin::../shared resources/img2.jpg")))
myRoot.add(TTextLeaf.create("!!! HadokeN !!!"))
myRoot.add(TTextLeaf.create("!!! HadokeN !!!"))

Local ypos = 600
Local length = 900
While Not KeyHit(KEY_ESCAPE)
	myroot.draw(ypos)
	SetBlend SHADEBLEND
	For Local i:Int = 0 To GraphicsWidth()-1
		SetRotation 180
		DrawImage overlay,GraphicsWidth()-i,GraphicsHeight()
		SetRotation 0
		DrawImage overlay,i,0
		i:+overlay.width-1
	Next
	SetBlend ALPHABLEND
	ypos:-1
	If length + ypos < 0
		ypos = 600
	EndIf
	Flip
	Cls
End While

It's part of a larger project, so won't work out of the box. But you should be able to figure it out.

Here you go:
' ---------------------------------------------
'  Tiny credits example - (c) 2006 by Grisu :o)
' ---------------------------------------------
SuperStrict 

Global CreditsTypeList:TList
Global AboutWindow:TGadget	   =CreateWindow(" Info", (GadgetWidth (Desktop ())-462)/2,(GadgetHeight(Desktop ())-272)/2,462,272,Null,WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS)
Global AboutCanvas:TGadget	   =CreateCanvas(3,3,200,267,AboutWindow)
Global AboutButton :TGadget    =CreateButton("OK",(500-110),250,70,20,AboutWindow,BUTTON_PUSH)

Global ScrollTimer :TTimer     =CreateTimer(27)  


Type CreditsType
    Field name:String
    Field val:Int
    Field y:Int
End Type 

Function AddCreditsLine(n:String,v:Int,y:Int)
    Local t:CreditsType=New CreditsType
    t.name=n
    t.val=v
    t.y=y
    CreditsTypeList.addlast t
EndFunction

Function Create_Credits()
' Create our tiny List of credit lines
Local ystart:Int=270

CreditsTypeList:TList=CreateList()

' Create Credits List Type Array
For Local i:Int=1 To 38
  Select i
  Case 1
	  AddCreditsLine("Mutant Gene",2,ystart+i*20)
  Case 2	
	  AddCreditsLine("Software",2,ystart+i*20)
  Case 3
	  AddCreditsLine("Stefan Sarbok",0,ystart+i*20)


  Case 5	
	  AddCreditsLine("Logo Artist",2,ystart+i*20) 
  Case 6  
	  AddCreditsLine("Troy Robinson",0,ystart+i*20) 

	
  Case 9	
	  AddCreditsLine("DFA Logo Artist",3,ystart+i*20) 
  Case 10  
	  AddCreditsLine("Aiga Rasch",0,ystart+i*20) 


  Case 12	
	  AddCreditsLine("Sound Libary",3,ystart+i*20) 
  Case 13	
	  AddCreditsLine("www.fmod.org",0,ystart+i*20) 
	 

  Case 15	
	  AddCreditsLine("Biographies",3,ystart+i*20)
  Case 16	
	  AddCreditsLine("www.3fragezeichen.de",0,ystart+i*20)


  Case 19	
	  AddCreditsLine("Lead Tester",1,ystart+i*20)
  Case 20	
	  AddCreditsLine("Constantin Maier",0,ystart+i*20)

  Case 22	
	  AddCreditsLine("Tester",1,ystart+i*20)
  Case 23	
	  AddCreditsLine("Björn Völlings",0,ystart+i*20)
  Case 24	
	  AddCreditsLine("Gulliver",0,ystart+i*20)
  Case 25	
	  AddCreditsLine("Kivi",0,ystart+i*20)
  Case 26	
	  AddCreditsLine("Leo",0,ystart+i*20)
  Case 27	
	  AddCreditsLine("Marguerida",0,ystart+i*20)
  Case 28	
	  AddCreditsLine("The Mad Hatter",0,ystart+i*20)

  Case 31	
	  AddCreditsLine("Special Thanks",3,ystart+i*20) 
  Case 32	
	  AddCreditsLine("Kosmos Verlag",0,ystart+i*20) 
  Case 33	
	  AddCreditsLine("EUROPA Tonstudio",0,ystart+i*20) 
  Case 34	
	  AddCreditsLine("REDIO Hosting",0,ystart+i*20) 


  Case 37	
	  AddCreditsLine("Dedication",2,ystart+i*20) 
  Case 38	
	  AddCreditsLine("Für einen Engel",0,ystart+i*20) 

  End Select 
Next 

End Function

Function Reset_Credits()
' Reset
  	ClearList( CreditsTypelist:TList )
    Create_Credits()
End Function 

Function Drawtext2(text:String,y:Int)
' Draws a centered line of text
Local Width:Int = ClientWidth(AboutCanvas) 
DrawText text , (Float(Width)/2.0)-(TextWidth(text)/2) , y '* Row

End Function 


Function Redraw_Credits()
' Refresh our credit canvas
Local ycheck:Int
    SetGraphics CanvasGraphics (AboutCanvas)
    SetBlend ALPHABLEND

    Cls 
	
    For Local t:CreditsType=EachIn CreditsTypeList
    SetAlpha 0.0
    Select t.val 
    Case 0 
       SetColor 255,255,255
    Case 1   
       SetColor 180,225,90
    Case 2   
       SetColor 250,80,120
    Case 3   
       SetColor 255,240,115
    End Select    

    t.y=t.y-1

    If t.y < 60 Then 

    If t.y>-5  Then SetAlpha 0.0
    If t.y>0  Then SetAlpha 0.1
    If t.y>5 Then SetAlpha 0.2
    If t.y>10 Then SetAlpha 0.3
    If t.y>15 Then SetAlpha 0.4
    If t.y>20 Then SetAlpha 0.5
    If t.y>25 Then SetAlpha 0.6
    If t.y>30 Then SetAlpha 0.7
    If t.y>35 Then SetAlpha 0.8
    If t.y>40 Then SetAlpha 0.9
    If t.y>45 Then SetAlpha 1.0

    Else 

    If t.y<260 Then SetAlpha 0.0
    If t.y<255 Then SetAlpha 0.1
    If t.y<250 Then SetAlpha 0.2
    If t.y<245 Then SetAlpha 0.3
    If t.y<240 Then SetAlpha 0.4
    If t.y<235 Then SetAlpha 0.5
    If t.y<230 Then SetAlpha 0.6
    If t.y<225 Then SetAlpha 0.7
    If t.y<220 Then SetAlpha 0.8
    If t.y<215 Then SetAlpha 0.9
    If t.y<210 Then SetAlpha 1.0

    EndIf 
    DrawText2 t.name,t.y

    ycheck=t.y
    Next    
    Flip 0

    If ycheck < -20 Then Reset_Credits()
    SetAlpha 1.0

EndFunction

' Main Loop -----------------------------------------------------------------------------------------------
Create_Credits()
Repeat
  WaitEvent()
  Select EventID()

    Case EVENT_WINDOWCLOSE
    End

    Case EVENT_TIMERTICK

    Select EventSource()
    
    Case ScrollTimer
      Redraw_Credits() 
    End Select 

    EndSelect 

Forever
ClearList( CreditsTypelist:TList )

' Main Loop End ---------------------------------------------------------------------------------------------- 


^^It's part of a larger project, but it works out of the box (using maxgui)... ;)

Nice ideas inside your code, many thanks.