Game Development Community

dev|Pro Game Development Curriculum

T2D Text Display Class - Updated

by Mark Mesich · 04/11/2006 (2:02 pm) · 26 comments

Download Code File

The following modification have been made to the original posting:

- Class names, file names, method calls etc. have been updated to fit with the latest naming conventions and account for the new names of the supporting objects.
- Melv May's coding suggestion has been incorporated to remove the need to add the method to t2dSceneWindow.h (previously fxSceneWindow2D.h) as mentioned in the original article.

In light of these changes the sample script might look like the following:

$test = new t2dTextObject() { scenegraph = sceneWindow2D.getSceneGraph(); };
$test.setText("Test String");	
	
// default font is Lucida Console, 14pt
$test.setFont("Tahoma");
$test.setSize(24);
	
// default font color is 0 0 0 255 (full black)
$test.setFontColor("255 255 255 255");
$test.setPosition("10 10");
$test.setLinearVelocityX(2);
	
// set the alpha of these to 0 to disable them (they won't draw for a slight speedup)
// they are disabled by default
$test.setBorderColor("0 0 255 255"); // R/G/B/A
$test.setBannerColor("255 0 0 255"); // R/G/B/A

About the author

Recent Blogs

Page«First 1 2 Next»
#21
07/21/2006 (4:15 am)
Thanks, Mark. I really want this functionality.

I'm using TGB Pro. In the About option in the Help menu, it lists the version as Torque2D Version 1.1.0 and Torque Game Builder Version 1.0.0.

I'm using Visual Studio 2005.

After having put the files into the source/T2D folder, I go into the Torque Game Builder\engine\compilers\VisualStudio 2005 folder and opening the project titled 'T2D'. I add t2dtextobject.cc and t2dtextobject.h to the project in the Source Files/T2D directory. Then I click on 'Rebuild T2D' under the 'Build' menu.

I don't get any errors at all, just two warnings. Only one of them refers to this new class: warning C4301: 't2dTextObject::integrateObject': overriding virtual function only differs from 't2dSceneObject::integrateObject' by const/volatile qualifier.

The other is a linker error but does not seem to be related to t2dtextobject - I only get this linker error when I rebuild the whole project, not when I just build the solution.

Then, when I run TGB, I get the following error: Unable to instantiate non-conobject class t2dTextObject. I'm completely stumped as to where I've gone wrong. :/
#22
07/21/2006 (7:38 am)
David, I am no expert with Visual Studio in fact I don't have 2005.

Just to clarify what I was suggesting above. Have you ever rebuilt TGB from source before? Try starting with a clean install of TGB, and rebuild from source without the t2dTextObject files. I think the problem sounds like you are not using the solution file (TD2 SDK.sln) Double click that file. It includes all the projectS (plural).

You can probably ignore the warning, but if you get a linker error that means the link failed and the executable you are running is an old one. Check the date+time stamp on the executable before you run it to verify this.

After the "solution" is building OK, then throw in the t2dTextObject files, and rebuild solution again, that should do the trick.
#23
07/30/2006 (10:05 pm)
*groan*

That doesn't seem to have worked, either. T2D still insists that I'm trying to "instantiate non-conobject class t2dTextObject". I can't for the life of me figure this out.

This confusion and frustration has made me wonder why such functionality isn't a part of T2D already. I mean, I would have thought drawing text to be a fairly common aspect of most games. Is there any chance this can be added to the next update, or for me to get sent via email a version of the engine that actually works with this new class added to it?
#24
07/30/2006 (10:12 pm)
David, sorry you have not successfully recompiled TGB (what that error message means- the executable you are running does not know what a t2dTextObject is). Start with the basics- learn to recompile the engine from source, then advance to adding in custom code like T2DTextObject. If it's too much to deal with- then you can always just use GUI objects instead. You can overlay a gui on top of your game and update the text in the GUI. See for example the score-keeping gui controls in some of the demos that come with TGB. That is the most common technique and that's the reason why the t2dTextObject is not part of the engine. Hope this helps.
#25
07/30/2006 (10:52 pm)
Wow. I checked out the gui text control functionality, and that does exactly what I need. What a relief!

Alex and Mark, thank you SO much for your efforts! Four weeks of frustration hasn't proven to be completely fruitless, even if it does mean I've ended up looking down a different avenue. ;)
#26
09/05/2006 (10:56 am)
First - Great resource!

Now for the "bad" part. I'm using mount() to bind the text to an object which is moving around in the scene (the players avatar). The camera is bound to the players avatar so they're always centered. As the player moves around the screen the t2dTextObject is "jittery" almost as if there is some float/int rounding issues going on. I'm trying to go through the source and see if I can find the problem, but if this is a known issue, please post up the patch!

Thanks!
Page«First 1 2 Next»