Game Development Community

[Solved] TorqueX.2D - Drawing Fonts

by AWannaBe · in Torque X 2D · 08/02/2011 (3:47 pm) · 2 replies

I've been trying to pick back up the TorqueX engine and move forward on some old projects and I've run in to a stumbling block of sorts.

I am currently struggling with the concept of writing a string using a SpriteFont to the screen.

I've been going through the TorqueCore code and it seems as though the GarageGames.Torque.GFX.FontRenderer class is what I might want to utilize.

If it is however I'm failing to see the most appropriate method of utilizing this class to render SpriteFonts to the screen.

The application is something that would be unrelated to a GUI.

Does anyone have any ideas on the best implementation? Something via a TorqueComponent perhaps?

I've tried a few different scenarios I've yet to achieve a result which renders a font to the screen.

It's been a few days now and it's either the coding from other work projects or the awesomely delicious break-beer which is causing me to have a dead hamster in my brain wheel.

#1
08/05/2011 (12:40 pm)
Is there a reason why you dont want to use the GUI/GUIText? It makes it real easy to create text, change the font, and it can all be updated dynamicly.

I think you can use SpriteBatch and SpriteFont with the XNA framework. Update DrawString in your Draw method.

batch.DrawString(font, text, position, Color.White);

Were "batch" is defined as SpriteBatch and "font" defined as SpriteFont

Good Luck :-) Check out the App Hub, they have lots of examples.
#2
08/07/2011 (1:04 pm)
I believe I found more or less what I was looking for with this thread.

@Aaron There are quite a few scenarios where someone might want to not use the GUI/GUIText. One of which is when you want to combine or write a SpriteFont directly onto a texture.

I did find that the proposed DrawTextOnTexture helper method can only be called in specific places within the game code otherwise you will write back essentially a blank texture to the screen.