Game Development Community

Mounting a GUIControl to a T2DSceneObject?

by rwillis · in Torque X 2D · 03/30/2008 (2:09 pm) · 4 replies

I have a GUIText object that I'd like to mount to a T2dSceneobject object but there's no mount method for a GUIControl object. Right now I'm constantly updating my GUItext object's ".Position" as the scene object I have it following moves and this causes the text to lag a little bit, but I think if I had the mount method for the control it wouldn't do this. Is there some other way already built in to do this? Or am I going to have to mess with the source?

#1
03/30/2008 (6:34 pm)
What about defining a new class such as:

public class T2DStaticSpriteWithText : T2DStaticSprite
    {
        public T2DStaticSpriteWithText()
        {
            _font = ResourceManager.Instance.LoadFont("arial16");
        }
 
        public override void Render(GarageGames.Torque.SceneGraph.SceneRenderState srs)
        {
            base.Render(srs);
            FontRenderer.Instance.DrawString(_font, Position, Color.Red, "MyText");
        }
 
        Resource<SpriteFont> _font;
    }

Of course, you would add properties for setting the text, color, offset, etc. Unfortunately, you would have to create these objects in code rather than through TXB.
#2
03/31/2008 (6:37 pm)
Thanks. That looks great. Does FontRenderer.Instance.DrawString method work for you? It doesn't seem to render anything.
#3
03/31/2008 (6:48 pm)
Yes, but one thing I forgot is that you need to adjust the position because DrawString's position has (0,0) in the upper left corner and scene objects have (0,0) in the screen center so your text may be drawing off screen.

I think using Position + (GUICanvas.Instance.Bounds.Extent / 2.0f) should do the trick.
#4
03/31/2008 (6:52 pm)
Cool. Thanks some more.