T2dTextObject
by Daniel Magnan · in Torque Game Builder · 04/13/2007 (10:28 am) · 8 replies
I am attempting to use a t2dTextObject to have text appear on the screen. For instance if a target is hit, have the damage value display briefly. I am currently using v1.1.3. The object gets created but the method "setText" is not recognized.
for example;
$test = new t2dTextObject(){scenegraph = $sg;};
$test.setText("test");
$test.setPosition(%pos);
When this is used I get the error "unknown command setText". setPosition works and looking at the source code setText is a method in t2dTextObject. What am I missing? Is there a better way to do what I am looking for?
edit: Unlike many other classes I cannot find any reference material for t2dTextObject.
for example;
$test = new t2dTextObject(){scenegraph = $sg;};
$test.setText("test");
$test.setPosition(%pos);
When this is used I get the error "unknown command setText". setPosition works and looking at the source code setText is a method in t2dTextObject. What am I missing? Is there a better way to do what I am looking for?
edit: Unlike many other classes I cannot find any reference material for t2dTextObject.
About the author
#2
04/13/2007 (11:52 am)
Daniel, t2dTextObject was an experiment on GG's Part to create accessor style properties ... similar to most OOP Languages, so setText and getText are not used ... rather, when you update the value of the 'text' "property" (field) it triggers the get/set methods and updates the object for you ... yes, I know, it's odd ... and nothing else in TGB really works the same way ... as I said, experiment ... but expect most of the other t2d* objects to start working the same way ... if I remember correctly, they stated they intend to use this for all future objects ... and eventually backport it to the existing ones ... but don't quote me on that ;)
#3
04/13/2007 (12:41 pm)
Thanks for the help. I suppose I should have tried to set it as a property before asking here.
#4
04/13/2007 (12:45 pm)
Honest mistake ... I had to ask the first time I used it too ... ;)
#5
$test = new t2dTextObject(){scenegraph = $sg;};
$test.text = "test";
$test.setPosition(%pos);
$test.setLayer("0");
Any ideas as to why nothing is appearing on the tilemap?
04/13/2007 (2:13 pm)
Still not having any luck. I do not get any error messages, but no text is appearing. I did update my graphics driver just to be sure, but that didn't help.$test = new t2dTextObject(){scenegraph = $sg;};
$test.text = "test";
$test.setPosition(%pos);
$test.setLayer("0");
Any ideas as to why nothing is appearing on the tilemap?
#6
The easiest way to set those things are in the call to new t2dTextObject. Just create a text object with the editor in an empty level, save the level and open it up with a text editor to see the parameters.
04/13/2007 (2:26 pm)
You most likely have to set the font and font size too. (and possibly also the size of the actual textobject). The easiest way to set those things are in the call to new t2dTextObject. Just create a text object with the editor in an empty level, save the level and open it up with a text editor to see the parameters.
#7
04/13/2007 (3:19 pm)
That is what I ended up doing, and it worked. Thanks for the suggestion Magnus.
#8
04/13/2007 (5:15 pm)
Magnus is correct, and this falls true for all objects created in script ... you have to assign sizes, and other various properties specific to that object, as none of the fields have defaults ...
Ricardo Vladimiro
Default Studio Name
I created a text object and took a look at the level file and I believe that the variable is text. So, try this:
$test.text = "test";
Hope it helps.