Again new functions.
wrap text and
ping pong text.
Note: Please change the font names while using the below code to suit your needs.
Rem ***** Main Source File *****
Rem Setup Screen
Sync On : AutoCam Off
Backdrop on : Color Backdrop Rgb(0,0,0)
`selfReminder: types and arrays keep things tidy, so use them anytime possible.
Type fontProperties
n As Integer
w As Integer
h As Integer
endType
DIM fonts(10) As fontProperties
fontCreate("fntRoman16.png", 1, 16, 16)
fontCreate("fntAstronBoy16.png", 2, 16, 16)
Do
fontWrite("!'^+%&/()=?-,#${[]}\`" , 0, 0, 1)
fontWrite("ABCDEFGHIJKLMNOPQRSTUVWXYZ" , 0, 16, 2)
fontWrite("abcdefghijklmnopqrstuvwxyz" , 0, 32, 1)
fontWrite("1234567890" , 0, 48, 2)
fontWriteCenter("THIS TEXT IS CENTER ALIGNED TEXT", 320, 64, 1)
REM NEW FUNCTION USAGE
xpos = WrapValueInt(xpos, 1, 0, 640)
fontWrite("WRAP BACKWARDS", 640-xpos, 90, 2)
fontWrite("WRAP FORWARDS", xpos, 106, 1)
REM NEW FUNCTION USAGE
wrap360# = WrapValueInt(wrap360#, 0.5, 0, 360)
c# = PingPongInt(c#, wrap360#, 0, 320)
fontWrite("PING PONG", c#, 130, 1)
angle = fontWriteEffect("RIGHT WAVING TEST", 320, 240, 1, angle, "right", 5)
angle = fontWriteEffect("LEFT WAVING TEST", 320, 350, 1, angle, "left", 10)
Sync
Loop
lbl_bmpFontFunctions:
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
`fontName = the path+filename of the bitmap font image
`fontNumber = the array number of the font
`fW and fH = a Characters width and height
Function fontCreate(fontName As String, fontNumber As Integer, fW As Byte, fH As Byte)
tmp = freeBitmap()
Load Bitmap fontName, tmp
Set Current Bitmap tmp
fonts(fontNumber).n = freeImage()
fonts(fontNumber).w = fW
fonts(fontNumber).h = fH
For y = 1 To 6
For x = 1 To 16
inc i
Get Image fonts(fontNumber).n+i-1, (x*fW)-fW, (y*fH)-fH, (x*fW), (y*fH)
Next x
Next y
Delete Bitmap tmp
CLS
Set Current Bitmap 0
EndFunction
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
`fontString = the string you want it to be written on screen
`x and y = screen coordinates where you want to write
`fontNumber = the array number of the font
Function fontWrite(fontString As String, x As Word, y As word, fontNumber As Integer)
For a=1 To len(fontString)
nr = fonts(fontNumber).n + (Asc(Mid$(fontString,a))-32)
If Image Exist(nr)=1 Then Paste Image nr, x+(a-1)*fonts(fontNumber).w, y, 1
Next a
EndFunction
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
`fontString = the string you want it to be written on screen
`x and y = screen coordinates where you want to write
`fontNumber = the array number of the font
Function fontWriteCenter(fontString As String, x As Word, y As word, fontNumber As Integer)
Length = len(fontString)
For a=1 To Length
nr = fonts(fontNumber).n + (Asc(Mid$(fontString,a))-32)
If Image Exist(nr)=1 Then Paste Image nr, (x+(a-1)*fonts(fontNumber).w)-((Length / 2.0)*fonts(fontNumber).w), y, 1
Next a
EndFunction
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
`fontString = the string you want it to be written on screen
`x and y = screen coordinates where you want to write
`fontNumber = the array number of the font
`ang = place holder to fake global ang variable
`effect = whether "left" or "right"
`waveHeight = height multiplier (best between 5-15)
Function fontWriteEffect(fontString As String, x As Word, y As word, fontNumber As Integer, ang As Word, effect As String, waveHeight As Byte)
ang = wrapvalue(ang + 1)
For a=1 To len(fontString)
nr = fonts(fontNumber).n + (Asc(Mid$(fontString,a))-32)
If effect = "left" Then y# = y + Sin(ang + a*waveHeight)*(len(fontString)-a)*5
If effect = "right" Then y# = y + Sin(ang + a*waveHeight)*a*5
If Image Exist(nr)=1 Then Paste Image nr, x+(a-1)*fonts(fontNumber).w, y#, 1
Next a
EndFunction ang
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
`num = place holder to fake a global variable
`speed = how fast wrapping will be
`min, max = minimum and maximum values of wrap
Function WrapValueInt(num As Float, speed As Float, min As Integer, max As Integer)
if num < min Then num = min
num = num + speed
If num => max Then num = min
EndFunction num
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
`num = place holder to fake a global variable
`wrap = depending on the function above, the angle value goes here
`min, max = minimum and maximum values of wrap
Function PingPongInt(num As Float, wrap As Float, min As Integer, max As Integer)
num = Sin(wrap)*Max + Max + Min
EndFunction num
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
lbl_helperFunctions:
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeImage()
Repeat
Inc i
Until Image Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function freeBitmap()
Repeat
Inc i
Until Bitmap Exist(i) = 0
EndFunction i
`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<