I'm trying to break a string into parts and reassemble them on the screen correctly, however, It seems GetTextWidth() Isn't getting the correct size on some characters when you change a text into a bitmap. Take a look:
[pbcode]
Dim GameFont(0)
CreateFont(26,1)
ThisString$="Some Level Title"
Length=Len(ThisString$)
X#=(ScreenW#/2)-(GetTextWidth(ThisString$)/2)
For X=1 To Length
ThisString2$=Mid$(ThisString$,X,1)
Text 2+GetTextWidth(ThisString2$),2+(X*22),ThisString2$
Next X
Sync: WaitKey
Wait 1000
SetFont 2
ThisString$="Some Level Title"
Length=Len(ThisString$)
X#=(ScreenW#/2)-(GetTextWidth(ThisString$)/2)
For X=1 To Length
ThisString2$=Mid$(ThisString$,X,1)
Text 32+GetTextWidth(ThisString2$),2+(X*22),ThisString2$
Next X
Sync: WaitKey
`Load the Font And shade it
Psub CreateFont(FontSize#,Color)
ThisNum=GetArrayElements(GameFont(),1)+1
If ThisNum=22
DeleteFont 1
EndIf
ReDim GameFont(ThisNum+1)
GameFont(ThisNum+1)=GetFreeFont()
LoadFont "Ariel",GameFont(ThisNum+1),FontSize#,1
MakeBitmapFont GameFont(ThisNum+1),$2F
TempImage=GetFreeImage(): CreateImage TempImage,FontSize#,FontSize#
RenderToImage TempImage
Color#=0
For X=1 To FontSize#
If X>(FontSize#*0.25)
Color#=Color#+((255/(FontSize#/2)))
If Color#>255 Then Color#=255
EndIf
`Red
If Color=1 Then LineC 0,0+x,FontSize#,0+x,RGB(255,Int(Color#),Int(Color#))
`Gold
If Color=2 Then LineC 0,0+x,FontSize#,0+x,RGB(255,255,Int(Color#))
`Blue
If Color=3 Then LineC 0,0+x,FontSize#,0+x,RGB(Int(Color#),Int(Color#),255)
Next X
RenderToScreen
BlendBitmapFont GameFont(ThisNum+1),TempImage
DeleteImage TempImage
EndPsub
[/pbcode]
The Arial font has variable width characters.
[pbcode]
Dim GameFont(0)
CreateFont(26,1)
ThisString$="Some Level Title"
Length=Len(ThisString$)
X#=(ScreenW#/2)-(GetTextWidth(ThisString$)/2)
For X=1 To Length
ThisString2$=Mid$(ThisString$,X,1)
Text 2+GetTextWidth(ThisString2$),2+(X*22),ThisString2$
Next X
Sync: WaitKey
Wait 1000
SetFont 2
ThisString$="Some Level Title"
Length=Len(ThisString$)
X#=(ScreenW#/2)-(GetTextWidth(ThisString$)/2)
For X=1 To Length
ThisString2$=Mid$(ThisString$,X,1)
; Text 32+GetTextWidth(ThisString2$),2+(X*22),ThisString2$
; center around width
CenterText 32,2+(X*22),ThisString2$
; right justify
Text 80-GetTextWidth(ThisString2$),2+(X*22),ThisString2$
Next X
Sync: WaitKey
`Load the Font And shade it
Psub CreateFont(FontSize#,Color)
ThisNum=GetArrayElements(GameFont(),1)+1
If ThisNum=22
DeleteFont 1
EndIf
ReDim GameFont(ThisNum+1)
GameFont(ThisNum+1)=GetFreeFont()
LoadFont "Ariel",GameFont(ThisNum+1),FontSize#,1
MakeBitmapFont GameFont(ThisNum+1),$2F
TempImage=GetFreeImage(): CreateImage TempImage,FontSize#,FontSize#
RenderToImage TempImage
Color#=0
For X=1 To FontSize#
If X>(FontSize#*0.25)
Color#=Color#+((255/(FontSize#/2)))
If Color#>255 Then Color#=255
EndIf
`Red
If Color=1 Then LineC 0,0+x,FontSize#,0+x,RGB(255,Int(Color#),Int(Color#))
`Gold
If Color=2 Then LineC 0,0+x,FontSize#,0+x,RGB(255,255,Int(Color#))
`Blue
If Color=3 Then LineC 0,0+x,FontSize#,0+x,RGB(Int(Color#),Int(Color#),255)
Next X
RenderToScreen
BlendBitmapFont GameFont(ThisNum+1),TempImage
DeleteImage TempImage
EndPsub
[/pbcode]
thanks kevin, but is there a way I can draw the letters in a horizontal fashion with the correct widths?
look closely, the widths are correct. If the weren't it wouldn't render any text correctly.