Hey, everyone. Thank's for checking out my post; I really need some help right now.
I've got a game going (if you help me I'll let you know what it is ^_^) and I really, really need to use the font "Verdana" in this game. It's a common TTF font that is on just about every computer in the universe, but there are two problems with TTFs:
1.) They take a full second to load each time a page has text on it. Built-in monospaced and bitmap fonts don't seem to take any time at all.
2.) They're anti-aliased. In other words, they look too pretty and glowy. I really need a pixelated font (similar to the monospaced) as strange as it sounds. It looks a lot better.
So what I need is a sample code of how to make a Bitmap font take upper- and lower-case letters into consideration. My font function right now blits everything in upper-case because my code is too simple. All I have is like,
~Based on the letter I inputted, go [x] pixels into font.png, take out that letter, and blit it.~
And it does blit it, but always in upper case :(. Like I said, any help would be REALLY useful, like if you know of any check commands such as string.case to make sure it blits the correct case! Thanks again!!!
Help: "Verdana" Font... TTF or Bitmap?
Moderators: Shine, Insert_witty_name
-
- Posts: 4
- Joined: Wed Sep 27, 2006 11:41 am
why not just test each character to see its case and blit the appropriate character?
i dont know the api/fuction to edit strings off the top of my head (i never did like string manipulation :-\) but i'd assume its something like:
personally thats how i'd do it, of course adding 25 more if statements for the other letters, and some more for numbers and others. you could even get a variable width font if you did that and just incremented the value dynamically on the image's width property.
ive no idea how many cpu cycles an if statement would be, especially in an interpreted language like lua, but ive programmed a small fighter (like super gem fighter) and have at least 100 (not including the if's for the enemy ai) if statements to see what frame of animation the characters are at and if they need to be incremented and theres no slow-down at all.
dunno if thats the easiest way, but that's how i'd get it done. hope it helps.
i dont know the api/fuction to edit strings off the top of my head (i never did like string manipulation :-\) but i'd assume its something like:
Code: Select all
myString = "ThIs Is My TeXt"
tempString = ""
tempString = myString.char(1) -- this variable now contains the string "T"
if tempString == "t" then
-- add code to draw the font bitmap to an offscreen image (with alpha on)
-- and then increment a variable with the width of the characters so you
-- know where to place the next one
elseif tempString == "T"
end
ive no idea how many cpu cycles an if statement would be, especially in an interpreted language like lua, but ive programmed a small fighter (like super gem fighter) and have at least 100 (not including the if's for the enemy ai) if statements to see what frame of animation the characters are at and if they need to be incremented and theres no slow-down at all.
dunno if thats the easiest way, but that's how i'd get it done. hope it helps.
LOL Thats a waste of time and effort, if you are looking to pixelate your fonts, then find a font thats pixelated using the TTF library.
Another thing is that if you load the FONT into a variable first its stored into memory first. Which means each time it is called it doesnt load from the memory stick and loads the character of the font. That often frees up alot of cycle time however it will never be as fast as drawing the system characters that are done through the SDK.
Also if you are dead set on using a .png system. I would use
if (string.upper(string.char(MyChar)) == string.char(MyChar)) then
-- I get a char offset! what?!
end
Another thing is that if you load the FONT into a variable first its stored into memory first. Which means each time it is called it doesnt load from the memory stick and loads the character of the font. That often frees up alot of cycle time however it will never be as fast as drawing the system characters that are done through the SDK.
Also if you are dead set on using a .png system. I would use
if (string.upper(string.char(MyChar)) == string.char(MyChar)) then
-- I get a char offset! what?!
end
heh, i said i didnt like string processing :-p
doesnt that just check to see if MyChar is uppercase? if it is it ignores the comment, if it doesnt, it doesnt go in the if-then code block?romero126 wrote:if (string.upper(string.char(MyChar)) == string.char(MyChar)) then
-- I get a char offset! what?!
end
Yes, it checks to see if the string is uppercase, If so offset the blit by x- which is the position of A of the Uppercase Letterblocks. If its not Uppercase then it uses the offset of a lowercase letter.
Generally it would be Uppercase and Lowercase should be based on the YAxis so the offset can be blit differently.
Makes things a little easier.
Generally it would be Uppercase and Lowercase should be based on the YAxis so the offset can be blit differently.
Makes things a little easier.