8 bit fonts
BlitzPlus Forums/BlitzPlus Programming/8 bit fonts
| ||
Hi, is there a way to use your own bmp's as '8 bit' (8x8 matrix type) fonts? I want to recreate those classic msx/c64/nintendo fonts but I my current project I'm handdrawing the words...wich feels kinda silly: espially with lot's of tekst. Any help or pointers would be appreciated. |
| ||
Yea, It's possible. We like to call it Bitmapped fonts :P Just create a matrix of all possible chars you'd want to use. in a bitmap. Devide the bitmap in "8x8" matrix. Id prefer to call it a frame. Now here's how i do my function. look up the ascii table http://www.asciitable.com/. you'll create the matrix image with frames that go from left to right. I create my words in the decimal order. Witch means that my frames match the decimal value. So frame 33 would be the ! character. Use Fontext free to create something similar. After you've generated you're bitmapped font just use the "LoadAnimImage" Command to load it in... Specify the right amount of frames. I created a function witch i recommen you do to. That parses a text string and generates a bitmapped font text. It's structure is similar to the text command. BMFText(X,Y,Text$,Center,BitmappedFont) Then i do the following. I use cases. If the first character in the Text$ is like a ! then i use the drawimage command to draw the Chr("!") value. witch is the 33'rd frame Example: Function BMFText(X%,Y%,Text$,Center,BMF%) Local BMHeight = 8 Tmp$ = Text$ For I = 1 to Len(Tmp$) Select Tmp$ Case Left(Tmp$) = Chr(33) Frame = 33 Case Left(Tmp$) = Chr(13) Y% = Y%% + BMHeight End Select Tmp$ = Right(Tmp$,Len(Tmp$-1)) DrawAnimImage BMF%,X%,Y%,Frame X% = X% + BMHeight ; Move the Position Next End Function IM not @ home right now so i didn't test the code i just wrote above, but it should help you along the way... |
| ||
Get MasterBeaker's FONText here. It makes the bitmap font for you, AND gives you a nice set of functions to get them into your game quickly (2d and 3d). |
| ||
Thanks for that code...I made numbers 0-9 as imaged and used a (score(/10^digit)mod 10) to decide which image i should use... this looks much more elegant. Thanks again. |
| ||
Oh, here's code I wrote to do basically the same: Function Write8(w$,wx,wy) Local wl,wa For wl=1 To Len(w$) wa = Asc(Mid$(w$,wl,1)) DrawImage letter(wa),wx+wl*8,wy Next End Function |
| ||
I'm Home and heres my function;Draw BMFonts Function DrawFnt(Start_X,Start_Y,TextString$,FNTNAME,HEIGHT%=0) StartX = Start_X StartY = Start_Y TextString$ = Upper(TextString$) While Len(TextString$) > 0 .Redo TextLength = Len(TextString$) Tmp$ = Left(TextString$,1) If TextLength-1 < 0 Exit EndIf TextString$ = Right(TextString$,TextLength-1) Frame = Asc(Tmp$)-33 If Tmp$ = Chr(32) ; SPACE StartX = StartX + HEIGHT% Goto Redo ElseIf Tmp$ = Chr(13) Then ; LINEBREAK StartY = StartY + HEIGHT% StartX = Start_X Else DrawImage FNTNAME,StartX,StartY,Frame StartX = StartX + HEIGHT% EndIf Wend End Function |
| ||
Thanks for that piece of code. It's a lot longer then mine though. ;) Ps. Why do you use the right$ and not the mid$ command? |
| ||
i dunno i guess i used it once and ever since.... |
| ||
I also see I used an array of images (1 to 128) instead of an animimage...hmmm..I wonder which is faster. |