Game Development Community

Printing Text

by Shiraz · in Torque X 2D · 02/20/2007 (11:10 pm) · 21 replies

I'm trying to print the prompt for the score on the screen. I used the statement...

DrawUtil.JustifiedText(ResourceManager.Instance.LoadFont("arial22"), new Vector2(0.0f, 0.0f), new SizeF(100f, 100f), TextAlignment.JustifyLeft, Color.White, "Score");

to try displaying something at the center of the screen. It compiles and runs but the text isn't there. Any ideas?
Page «Previous 1 2
#1
02/21/2007 (9:43 am)
Check out the torquecombat template, it writes a clock every second which is a good example on how to write text to the screen. I'm not at home to debug your line, sorry. If no one answers you before I get home I'll take a look then (unless you get what you want from the combat template)

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#2
02/21/2007 (10:31 am)
I actually copied all that code into my solution with the same net result. :-(
#3
02/21/2007 (11:39 am)
What color is the background of where you are trying to write the text? Do you see anything at all, or does it look like with the code to write the text there is no difference at all than when you don't have the code?

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#4
02/21/2007 (1:53 pm)
There's no difference at all. I tried adding the above code to ProcessTick of MovementComponent of the StarterGame, figuring it's the simplest example with not much extraneous code. Still no sign of the text.
#5
02/21/2007 (1:59 pm)
When you run the TorqueCombat demo without modifications, do you see the clock?

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#6
02/21/2007 (2:03 pm)
Yes I do.

And I just added that code to the StarterGame and nothing shows.
#7
02/21/2007 (2:58 pm)
Shiraz, want to zip your project and post it? I can take a look at it in a couple hours.

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#8
02/21/2007 (3:09 pm)
Cool. Thanks. I sent it (StarterGame version) in an email to you.
#9
02/21/2007 (6:56 pm)
Actually I would advise looking into the GUI system as that would be a much more viable option in the long run when things get more complex and the like. Look into how TorqueCombat uses GUIs and inplement your own class with a GUIText object. I find the GUI system to work very well for everything that I have done.
#10
02/21/2007 (7:41 pm)
Do you have an snipet of code you can send as an example?
#11
02/21/2007 (8:09 pm)
Sure here's is what you are going to want to do:

1. Create a class for your the GUI content that you are going to want to be displayed.

(example)
class GameScreenGUI : GUISceneview, IGUIScreen, ITickObject
    {
        GUIText _playerOneScore;
        GUIText _playerTwoScore;

        public GameScreenGUI()
        {
            GUIStyle sceneStyle = new GUIStyle();
            
            this.Name = "GameScreenGUI";
            this.Style = sceneStyle;

            GUITextStyle textStyle = new GUITextStyle();
            textStyle.FontType = "arial16";
            textStyle.TextColor = Color.White;
            textStyle.SizeToText = true;

            _playerOneScore = new GUIText();
            _playerOneScore.Style = textStyle;
            _playerOneScore.Text = "0";
            _playerOneScore.Position = new Vector2(60f, 10);
            _playerOneScore.Visible = true;
            _playerOneScore.Folder = this;

            _playerTwoScore = new GUIText();
            _playerTwoScore.Style = textStyle;
            _playerTwoScore.Text = "0";
            _playerTwoScore.Position = new Vector2(710f, 10);
            _playerTwoScore.Visible = true;
            _playerTwoScore.Folder = this;
        }

        public void ProcessTick(Move move, float dt)
        {
                _playerOneScore.Text = GameManager.Instance.PlayerOne.Score.ToString();
                _playerTwoScore.Text = GameManager.Instance.PlayerTwo.Score.ToString();
        }

Obviously your storage for your score is going to be in a different spot so act accordingly.

Also you are going to have to call this function, probably somewhere in beginRun, in order to initialize this GUI screen.
GUIUtil.InitGUIScreens("ShapeSports.GUI");

This will initialize all GUI classes that implement the IGUIScreen interface.

Finally, to load the GUI call
GUICanvas.Instance.SetContentControl("GameScreenGUI");
right before you load your level.
#12
02/21/2007 (10:08 pm)
Thanks. That was a lot simpler to work with than the TorqueCombat code.

I figured out the problem too. I was setting the .Folder to whatever SceneView came with the new code instead of the one in my existing code! Ack! I guess that's why I'm posting this in Getting Started. ;-)
#13
02/21/2007 (10:23 pm)
Yeah, the same thing happened to me. Took me forever to realize that I was missing the folder line.
#14
02/21/2007 (11:39 pm)
That's the true joy of programming, isn't it? Realizing you've missed one simple but crucial line that prevents all your efforts from going to hell.
#15
04/02/2007 (3:57 am)
So I've got all of this setup, but for the life of me I can't figure out the tick system.

How do I get a tick to activate on the UI? It's not a real object, and it's instantiated using the GUICanvas.Initscreens, so I don't seem to have an object reference.
#16
04/02/2007 (7:34 am)
Why do you need ticks on your GUI?

www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#17
04/02/2007 (11:52 am)
Override OnRegister() and inside do this:

public override bool OnRegister()
        {
            if (!base.OnRegister())
                return false;

            // tell the process list we can receive ticks
            SetTicking();

            return true;
        }
#18
05/06/2007 (2:30 pm)
I tried using the code above and it prints to the screen alright, but the processTick method doesn't work. I tried using the overrided method Robert supplied but the SetTicking method isn't recognized. What's needed to be done to get processTick to work inside a non-component class type?

EDIT: I've found the answer to my question. To get processTick to work inside a non-component class type you just have to create an object from that class and then call processTick on it (Make sure the class uses ITickObject interface). I did this inside another component's processTick method, of which I created the non-component class type inside of.
#19
05/06/2007 (8:07 pm)
Btw, i think you should look at overriding Update() instead of the tick stuff, just from a performance perspective.
#20
05/08/2007 (7:17 am)
On the printing text subject...has anyone gotten the new bitmap font template thing in the XNA refresh to work?

I cant figure out what the hell Im expected to do with it.
Page «Previous 1 2