Displaying text?
by Vern Jensen · in Torque Game Builder · 10/08/2007 (10:58 am) · 11 replies
I'd like to display some text in my game... I know where are resources available to add this, but as of the 1.5 release of TGB, it seems like t2dTextObject should handle such things. Problem is, I don't know how to use it, and haven't been able to find any documentation or sample code for it.
Anyone know how to use this object? Or how to display text using any other method? (Using a real font, not pre-rendered characters.)
Anyone know how to use this object? Or how to display text using any other method? (Using a real font, not pre-rendered characters.)
#2
10/09/2007 (10:00 am)
That looks great, but still no documentation or sample code on how to use the t2dTextObject class itself. Any links to code / documentation for that?
#3
10/09/2007 (12:48 pm)
What kind of thing are you after? Changing text or font via script?
#4
10/09/2007 (4:18 pm)
I was to display text in my game, via script, using some sort of a font. It will be used to show each level's name (there are over 50) before the level starts. My guess is that t2dTextObject would have all the properties of any normal t2dScenObject, so I could scale it, move it, change its blendColor, etc. I jjust don't know how to use that object. I've tried things like creating it and setting its "text" field to what I want, but that does nothing. I need some documentation or sample code on how to use it. I'm sure it's not that hard, it's just hard when you don't have any documentation.
#5
I also noticed when creating it using the GUI editor that the font is obviously scaled bigger if you create fairly large text. Any way to get it to render correctly at large resolutions, instead of being so pixelized? Just curious. I don't actually need it that big.
10/09/2007 (4:35 pm)
Ahhh, I see what you're getting at. Just noticed that the TextObject is an object in the editor that you can create using the GUI method. Yes, I want to create it via script instead. Any sample code for such a thing?I also noticed when creating it using the GUI editor that the font is obviously scaled bigger if you create fairly large text. Any way to get it to render correctly at large resolutions, instead of being so pixelized? Just curious. I don't actually need it that big.
#6
In terms of creating new t2dTextObjects on the fly, you do it just as any other t2dSceneObject.
When you add a font size to the object, you must have the font with that size added to it. See the FontBoy tool for more details about it, but essentially, when you add a custome font, you must also add the different sizes.
Please note that you have used the term GUI. Using a t2dTextObject and a GUI text object is completely different (to the best of my knowledge). The above ise for an actual scene object rather than a GUI object.
If you want to create a GUI object, I would recommend just creating a GUI then opening up the .cs file in your editor and checking out exactly what needs to be called to create it nicely for you. However, remember that GUI coordinates are different from the scene coordinates, they start at 0,0 in the top left corner, not in the center of the screen.
Good luck, hope this helped out a little bit.
10/09/2007 (4:52 pm)
Firstly, grab, install and use the FontBoy resource above. It will help handle everything you need to get custom fonts in your game.In terms of creating new t2dTextObjects on the fly, you do it just as any other t2dSceneObject.
%textObj = new t2dTextObject(name)
{
param = val
};
%textObj.text = "Hello Vern!";
%textObj.addFontSize(16);When you add a font size to the object, you must have the font with that size added to it. See the FontBoy tool for more details about it, but essentially, when you add a custome font, you must also add the different sizes.
Please note that you have used the term GUI. Using a t2dTextObject and a GUI text object is completely different (to the best of my knowledge). The above ise for an actual scene object rather than a GUI object.
If you want to create a GUI object, I would recommend just creating a GUI then opening up the .cs file in your editor and checking out exactly what needs to be called to create it nicely for you. However, remember that GUI coordinates are different from the scene coordinates, they start at 0,0 in the top left corner, not in the center of the screen.
Good luck, hope this helped out a little bit.
#7
*Duh*. [Vern smacks himself in the side of the head.] I should've figured that out, but thanks for the reminder.
Thanks also for the sample code. The "addFontSize" call was what I was missing, and it don't work without that.
Question: when you add a font size, it is generating Bitmaps for all the characters, and loading those into memory? Because that would take up a lot of VRAM if you had a lot of fonts with large sizes created. Just want to know so I can keep it to a minimum if that's what it's really doing.
10/10/2007 (11:02 am)
Quote:If you want to create a GUI object, I would recommend just creating a GUI then opening up the .cs file in your editor and checking out exactly what needs to be called to create it nicely for you.
*Duh*. [Vern smacks himself in the side of the head.] I should've figured that out, but thanks for the reminder.
Thanks also for the sample code. The "addFontSize" call was what I was missing, and it don't work without that.
Question: when you add a font size, it is generating Bitmaps for all the characters, and loading those into memory? Because that would take up a lot of VRAM if you had a lot of fonts with large sizes created. Just want to know so I can keep it to a minimum if that's what it's really doing.
#8
It's there for normal sprites, so I'd assume there'd be a way to turn on a filter for text too?
10/10/2007 (11:18 am)
Oh, and is there a way to turn on anti-aliasting for the text? I notice that if you blow it up real big, there is no antialiasing.It's there for normal sprites, so I'd assume there'd be a way to turn on a filter for text too?
#9
Phillip, thanks so much for all the help!
10/10/2007 (11:28 am)
Okay, nevermind, looks like anti-aliasing is on after all. Phillip, thanks so much for all the help!
#10
I forgot to mention that once you add a font size to the object, you must tell it which font size to use (I think):
And in terms of VRAM, I don't think it loads the images into the ram before the font size has been actually applied to the object. I could be wrong, however. Maybe someone else knows?
10/10/2007 (1:21 pm)
You got it working? Sweet, glad I could help.I forgot to mention that once you add a font size to the object, you must tell it which font size to use (I think):
%textObj.fontSizes = 16;
And in terms of VRAM, I don't think it loads the images into the ram before the font size has been actually applied to the object. I could be wrong, however. Maybe someone else knows?
#11
10/10/2007 (2:09 pm)
I wonder if it actually creates an image in RAM for each character in the alphabet, or if it just creates an image for the string you want displayed. So for "Hello Vern!" it just creates a bitmap large enough to contain that text, rather than a Bitmap for all possible characters it might display. If so, then it's not nearly the danger in terms of RAM consumption that I initially thought it might be.
Associate Phillip O'Shea
Violent Tulip
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13348
It is something that comes in handy when using custom fonts. It describes useages and whatnot as well. Very handy.