Heres some code for a couple of simple bitmap font text effects I made. You can get the font used in it here:
http://dbfinteractive.com/index.php?topic=311.0It also works with the other bitmap fonts on this site. And heres the code:
Const GRAPHICS_W = 800
Const GRAPHICS_H = 600
Const FONT_W = 16
Const FONT_H = 16
Const CHARS$ = " !@#$%+'[] ,-./0123456789:;(=)? ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Const LETTERS = 64
Const FONT_MASK = -16777216
Dim font(LETTERS*FONT_W, FONT_H)
Graphics GRAPHICS_W, GRAPHICS_H, 32, 2
SetBuffer BackBuffer()
BitmapFontLoad("Com.png")
Global old_time = MilliSecs()
Global frame_count, fps
inc=2: y=100: x=100
While Not KeyHit(1)
Cls
WobbleText(x, y, count, 50, "SOMETHING IS GOING ON")
WobbleText(x-20, y+100, count+5, 40, "ITS A WAVY TEXT DEMO !")
StretchyText(x, y+300, FONT_H, 50, "STRETCHY TEXT")
count=count+1
x=x+inc
If x+(20*16) >= GRAPHICS_W Or x < 0 Then inc=-inc
FPS()
Flip 0
Wend
Function StretchyText(x_pos, y_pos, min, max, txt$)
length = Len(txt$)
LockBuffer BackBuffer()
For char=0 To length-1
;GET THE POSITION IN FONT OF THE LETTER
letter$=Mid(txt$, char+1, 1)
For frame = 1 To LETTERS
If letter$ = Mid(CHARS$, frame, 1) Then Exit
Next
frame=frame-1
char_x = x_pos + char*FONT_W
;DRAW LETTER
For x=0 To FONT_W-1
height = (min+max+(Sin(char_x+x)*max)-1)
char_y = y_pos - (height / 2)
y_inc# = Float(FONT_H)/height
font_x = frame*FONT_W+x
font_y#=0
draw_x = char_x+x
For y=0 To height
draw_y = char_y+y
If font(font_x, font_y#) <> FONT_MASK
WritePixel(draw_x, draw_y, font(font_x, font_y#))
EndIf
font_y# = font_y#+y_inc#
Next
Next
Next
UnlockBuffer BackBuffer()
End Function
Function WobbleText(x_pos, y_pos, deg, intensity, txt$)
length = Len(txt$)
LockBuffer BackBuffer()
For char=0 To length-1
letter$=Mid(txt$, char+1, 1)
;GET THE POSITION IN FONT OF THE LETTER
For frame = 1 To LETTERS
If letter$ = Mid(CHARS$, frame, 1) Then Exit
Next
frame=frame-1
x_mod = char*FONT_W
;DRAW LETTER
For x=0 To FONT_W-1
wobble=Sin((char*FONT_W)+x+deg)*intensity
font_x = frame*FONT_W+x
For y=0 To FONT_H-1
draw_y = y_pos+y+wobble
draw_x = x_pos+x_mod+x
If font(font_x, y) <> FONT_MASK
WritePixel(draw_x, draw_y, font(font_x, y))
EndIf
Next
Next
Next
UnlockBuffer BackBuffer()
End Function
Function BitmapFontLoad(filename$)
tmp=LoadImage(filename$)
w=ImageWidth(tmp)
h=ImageHeight(tmp)
SetBuffer ImageBuffer(tmp)
LockBuffer
For y=0 To h-1
y_mod = y Mod FONT_H
For x=0 To w-1
font(((y/FONT_H)*w)+x, y_mod)=ReadPixelFast(x, y)
Next
Next
UnlockBuffer
SetBuffer BackBuffer()
FreeImage(tmp)
End Function
Function FPS()
If MilliSecs() > old_time+1000
old_time = MilliSecs()
fps=frame_count
frame_count=0
EndIf
Color 255, 255, 255
Text 0, 0, "FPS: "+fps
frame_count=frame_count+1
End Function I'm working on porting these to C, but I am getting segfaults at the moment for poking about in the wrong bits of memory. Hopefully I should have that fixed in a bit tho




