Game Development Community

T2dTextObject & mouse events

by amaranthia · in Torque Game Builder · 03/10/2008 (10:52 am) · 2 replies

Has anyone got mouse events to work with the t2DTextObject object?

My following text object displays, but I can't get mouse events to trigger the same way I can with image objects.

new t2dTextObject(%name) {
      sceneGraph = %this;
      class = %class;
      canSaveDynamicFields = "1";
      Position = %position;
      size = "13.425 3.000";
      BlendColor = "0 0 0 1";
      text = %text;
      font = "Arial Black";
      hideOverflow = "0";
      textAlign = "Center";
      lineHeight = "3";
      aspectRatio = "0.830796";
      autoSize = "1";
      fontSizes = "20";
      textColor = "0 0 0 1";
      useMouseEvents = "1";
      customType = "201";
   };

Note: I did add a custom field that could be causing the problem (customType). Does t2dTextObject support custom fields?

#1
03/10/2008 (3:01 pm)
I just tried this and it worked for me. Try hardcoding your class just to see if it works. It may be a case of the %class not working.
function TestText::onMouseEnter(%this, %modifier, %worldPos)
{
   echo("Mouse Enter");
}
function GameLevel::onLevelLoaded(%this)
{
      new t2dTextObject(newText) {
      sceneGraph = %this;
      class = "TestText";
      canSaveDynamicFields = "1";
      Position = "0 0";
      size = "13.425 3.000";
      BlendColor = "0 0 0 1";
      text = "Test Text";
      font = "Arial Black";
      hideOverflow = "0";
      textAlign = "Center";
      lineHeight = "3";
      aspectRatio = "0.830796";
      autoSize = "1";
      fontSizes = "20";
      textColor = "0 0 0 1";
      useMouseEvents = "1";
      customType = "201";
      }; 
   
}
#2
03/10/2008 (3:58 pm)
Found the problem. I was assigning a class called "machine" which was assigned to an image object. :)