Want share this code to show texts. Can use for credits, stages, misions, or any thing what not requiere change the content of text. Admit font, size and speed as params.
Is not finished, i will add other functions to change the text, remove...
May be need adjust the speed depend of your machine. Because was progrmmed in a jurassic PC.

Is animated and very simple to use. I hope help any body making... uhhh any thing?

Code: Select all
;{ TEXTOS ESPECIALES
Structure gtxt_textos
txt.s
spr.i
x.i
y.i
w.i
h.i
wv.f
hv.f
nx.f
ny.f
spd.a
fade.l
show.b
EndStructure
Global NewList gtxt.gtxt_textos()
Procedure gtxtAdd(x,y,txt.s, ink.l=$ff0044ff,border.l=$ffffffff,bordW.d=2, shadow.d=4,fontname.s="Arial",size.a=30, show.b=0, spd.a=3)
;Añade un texto nuevo
;Add a new text
Protected.i i= CreateImage(#PB_Any, 100,100)
Protected.c w,h
Protected.i f= LoadFont(#PB_Any,fontname,size)
StartDrawing(ImageOutput(i)):DrawingFont(FontID(f)):w= TextWidth(txt)+12:h= TextHeight(txt)+12:StopDrawing()
AddElement(gtxt())
gtxt()\txt= txt
gtxt()\fade= 0
gtxt()\show= 0
gtxt()\spd= spd
gtxt()\show= show
gtxt()\x= x
gtxt()\y= y
gtxt()\w= w
gtxt()\h= h
gtxt()\wv= h
gtxt()\hv= h
gtxt()\nx= x
gtxt()\ny= y
gtxt()\spr= CreateSprite(#PB_Any,w,h,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(gtxt()\spr))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight(),$00000000)
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
DrawingFont(FontID(f))
If shadow
For x=1 To shadow
DrawText(4+x+bordW,4+x+bordW, txt, $ff000000)
Next x
EndIf
If bordW
For y=-bordW To bordW
For x=-bordW To bordW
DrawText(4+x,4+y,txt, border)
Next x
Next y
EndIf
DrawText(4,4,txt, ink)
StopDrawing()
FreeImage(i)
FreeFont(f)
EndProcedure
Procedure gtxShow(delay=20)
;Controla los fundidos de los textos. Poner en el bucle principal.
;Fade of texts controls. Put in the main loop.
Static timer
ForEach gtxt()
If gtxt()\show
DisplayTransparentSprite(gtxt()\spr,gtxt()\nx,gtxt()\ny, gtxt()\fade)
If gtxt()\fade<255
gtxt()\fade+gtxt()\spd: If gtxt()\fade>255:gtxt()\fade=255:EndIf
zoom.d= 1 + (255-gtxt()\fade) * 0.01
gtxt()\wv= zoom * gtxt()\w
gtxt()\hv= zoom * gtxt()\h
gtxt()\nx= gtxt()\x-(gtxt()\wv/2)
gtxt()\ny= gtxt()\y-(gtxt()\hv/2)
ZoomSprite(gtxt()\spr, gtxt()\wv, gtxt()\hv)
EndIf
Else
If gtxt()\fade>0
gtxt()\fade-gtxt()\spd: If gtxt()\fade<0:gtxt()\fade=0:EndIf
zoom.d= 1 + (255-gtxt()\fade) * 0.01
gtxt()\wv= zoom * gtxt()\w
gtxt()\hv= zoom * gtxt()\h
gtxt()\nx= gtxt()\x-(gtxt()\wv/2)
gtxt()\ny= gtxt()\y-(gtxt()\hv/2)
ZoomSprite(gtxt()\spr, zoom * gtxt()\w, zoom * gtxt()\h)
DisplayTransparentSprite(gtxt()\spr,gtxt()\nx,gtxt()\ny, gtxt()\fade)
EndIf
EndIf
Next
EndProcedure
;}
CompilerIf #PB_Compiler_IsMainFile
;{ sistema 3D
InitEngine3D(#PB_Engine3D_DebugLog):InitSprite():InitKeyboard():InitMouse()
OpenWindow(0, 0,0, 1280,720, "TextFX",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0),WindowHeight(0), 0, 0, 0)
CreateCamera(0,0,0,100,100):MoveCamera(camara,-3.06,47.28,-35.89,#PB_Absolute):CameraLookAt(0,0,5,0):CameraBackColor(0,$332211)
CreateLight(0,$ffffff,23,23,23)
e= CreateEntity(#PB_Any,MeshID(CreateCube(#PB_Any,15)),MaterialID(CreateMaterial(#PB_Any,#Null,$0000ff)))
;}
gtxtAdd(640,100,"Pulsa la tecla V - Press key V",$ffffffff,ff000000,2,4,"Arial",30,1)
gtxtAdd(640,300,"PureBasic",$ff0044ff,$ffffffff,2,4,"Times New Roman",40,0,2)
gtxtAdd(640,350,"Simply the best!",$ffff2200,$ffffff00,4,4,"Impact",30,0,4)
gtxtAdd(640,400,"Another text?",$ff00ffff,$ff00ff00,4,4,"Lucida console",30,0,5)
Repeat
While WindowEvent():Wend
ExamineMouse(): ExamineKeyboard()
If KeyboardReleased(#PB_Key_V)
ForEach gtxt()
gtxt()\show !1
Next
EndIf
If KeyboardReleased(#PB_Key_C)
SetClipboardText("MoveCamera(camara,"+StrD(CameraX(camara),2)+","+StrD(CameraY(camara),2)+","+StrD(CameraZ(camara),2)+",#PB_Absolute)")
EndIf
RotateEntity(e,0.5,1,2,#PB_Relative)
renderTime= RenderWorld()
x=0:y=0
gtxShow()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
CompilerEndIf