Click here to Skip to main content
15,886,006 members
Articles / Game Development / XBox

XNA Batched Text Output

,
Rate me:
Please Sign up or sign in to vote.
4.58/5 (6 votes)
2 Jul 20073 min read 45.7K   268   19  
A batched text output component that is useful for debugging XNA projects.
/* 
 * TextOutput Sample Application
 * 
 * System to display a list of text output in a single sprite batch output for XNA.
 * 
 * Author: Kurt Wesner, Bob Bradley
 * Place: University of Tennessee at Martin
 * Date:  July 02 2007
 * 
 */
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using UTM.CSIS.Xedge;

#endregion

namespace TextOutputDemo
{
    /// <summary>
    /// This is a demo for TextOutput.
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;
        TextOutput textOutput;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);

            this.Window.AllowUserResizing = true;

            this.Components.Add(textOutput = new TextOutput(this));
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {

            }
            this.IsMouseVisible = true;


        }

        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
                content.Unload();
            }
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.Black);


            MouseState currentMouseState = Mouse.GetState();
            textOutput.WriteAt(0, 0, "Demonstration of XNA TextOutput component.");
            textOutput.FontRotation = MathHelper.ToRadians((float)currentMouseState.X);
            textOutput.writeAtMouse("Mouse is at \r\n X: " + currentMouseState.X + " Y: " + currentMouseState.Y, Color.Yellow);
            textOutput.FontRotation = 0;//reset font rotation to 0 or else everything would be rotated.
            textOutput.WriteAt(50, 50, "Hello World!");

            textOutput.WriteAt(100, 100, "Game Time: " + gameTime.TotalRealTime.ToString(), Color.Red);

            base.Draw(gameTime);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Bob Bradley is a full time Computer Science instructor at the University of Tennessee at Martin. He has been preoccupied with computers since his first Commodore Vic-20. He is currently interested in XNA/XBox-360 programming!

Written By
United States United States
Currently a senior at the University of Tennessee at Martin: Computer Science.

Comments and Discussions