Text in a level
by Tony Pitman · in Torque X 2D · 05/24/2010 (10:40 pm) · 7 replies
I want to output text onto a T2DStaticSprite. What is the easiest way to do this? I would like it to be automatically adjusted for the screen resolution and things like that just like a GUIText object would do, but I need it to be associated and preferablly mounted on a T2DStaticSprite.
I thought about rendering the text and then creating all of the many words and sentences, but that would require a ton of new sprites. Seems like there should be an easier way to draw text onto a sprite. Is there?
I thought about rendering the text and then creating all of the many words and sentences, but that would require a ton of new sprites. Seems like there should be an easier way to draw text onto a sprite. Is there?
#2
05/25/2010 (6:42 am)
I will search for the thread. If anyone remembers where it is I would appreciate you letting me know.
#3
http://www.torquepowered.com/community/forums/viewthread/73813
http://www.torquepowered.com/community/forums/viewthread/102923
05/25/2010 (7:01 am)
Two related threads I just dug up with a quick search...http://www.torquepowered.com/community/forums/viewthread/73813
http://www.torquepowered.com/community/forums/viewthread/102923
#4
05/25/2010 (7:33 am)
Thank you. I will look at these.
#5
05/25/2010 (8:12 am)
I have one of the methods sort of working. I am using the RenderTarget2D stuff and creating a material that I draw into. This works except for one final thing. The size of the material that gets created is a different size depending on the length of text. When it gets rendered onto the T2DStaticSprite object it gets stretched to fill the static sprite. How can I prevent the stretching?
#6
Instead of using the font.measuresize to get the size for the RenderTarget2D I figure out the original size of the T2DStaticSprite and use that as the size. Then when I render into it the text shows up without stretching because the RenderTarget is the same size as the sprite originally was. This seems to work fine.
05/25/2010 (10:17 am)
Although I would still like to know how to apply the texture without having it stretched I did come up with another way to do it.Instead of using the font.measuresize to get the size for the RenderTarget2D I figure out the original size of the T2DStaticSprite and use that as the size. Then when I render into it the text shows up without stretching because the RenderTarget is the same size as the sprite originally was. This seems to work fine.
#7
05/25/2010 (10:35 am)
Yes, that sounds perfectly okay. SpriteBatch will render to the size you tell it to. MeasureSize() is really for when you want to adjust to the size of the text rather than the other way around.
Torque Owner Duncan Colvin
To render to a texture you'll need to do some XNA coding. In particular you'll need to look into using SpriteBatch and RenderTargets.
There was a thread on outputting text last year I think.