XNA – Displaying Centred Text

Going through the forums today I can across a post where a user was asking about displaying text on the screen so that it was centred.

Here is a couple of quick lines of code that will allow you to display some text on the screen that is centred. When using this sample it will calculate the length of the text, then work out the exact centre of the screen. Then using the normal sprite origin functions it will work out the exact centre of the text and position it on the screen.

To add a little bit of flare to it I have also set up the sample so that it will also draw a shadow on the text.

To start with create a new windows game project (Note that this will also work with an Xbox 360 project). Next we need to add a sprite font to the application, with out this we are not going to be able to draw the text.

At the top of the application add the following to the code,

SpriteFont gameFont;


Now add the sprite font object to the content pipeline, go to the solution explorer and right click on the “content” item. When there select a new folder and change this folders name to “Fonts”. Once done right click on the “Fonts” folder and select ad new item, this time select sprite font and call it “GameFont.spriteFont”.

When you do add the font you are going to have to edit the xml file and set the fonts name. Change the Fonts name inside the spritefont file to look like the line below.

<FontName>Lucida Console</FontName> 

With the Font set up we now need to load it. Inside your main application, add the following line of code to the LoadContent Call.

// TODO: use this.Content to load your game content here
this.gameFont = Content.Load<SpriteFont>(@”Fonts\GameFont”); 


The last stage is to change your Draw call to look like the following.

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name=”gameTime”>Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)

            // TODO: Add your drawing code here
            string PressStartString = “Centered Text”;
            Vector2 PressStartSize = gameFont.MeasureString(PressStartString);


                new Vector2((this.graphics.GraphicsDevice.Viewport.Width / 2) + 2, (this.graphics.GraphicsDevice.Viewport.Height / 2) + 2),
                Color.Black, 0.0f,
                new Vector2(PressStartSize.X / 2, PressStartSize.Y / 2),
                1.0f, SpriteEffects.None, 0.0f);

                new Vector2(this.graphics.GraphicsDevice.Viewport.Width / 2, this.graphics.GraphicsDevice.Viewport.Height / 2),
                Color.White, 0.0f,
                new Vector2(PressStartSize.X / 2, PressStartSize.Y / 2),
                1.0f, SpriteEffects.None, 0.0f);




In the above code the first thing that we do is clear the screen so that it is ready for us to draw. Next we define the string of text that we wish to display. On the next line we measure the text so that we know how many pixels the total string will be using.

With the next section of code we are actually drawing it onto the screen. We use the Graphics Devices View port to decide where the centre of the screen is, and then set the sprites origin to the centre of the sprites texture. Doing this will allow us to position the text at the exact centre of the screen.

I do hope that this helps someone, but in any case this is based on a similar function that I use in several of my applications.

I did create this sample using the XNA 2.0 system and Game Studio, but the process will work in the XNA 1.0 Refresh system.

Cross Post from www.virtualrealm.com.au

XNA 2.0 Beta

As you all know by now the XNA 2.0 Beta is finally out and ready for all to use. Well today I have finally had a change to play with it and start to see what has changed.

After the install I did not see much that would affect the way I do things, other then the ability to use the full Visual Studio System. With a Presentation happening next week I decided to focus all of my trial and testing towards it. There for I have dived more into small samples and a Small game. I do not plan on doing much with the Networking classes in the beginning, I want to make sure that the things I do now are not affected to much.

Going though my current samples I have not seen any show stoppers or problems other then some cosmetic things, for which I will be posting on the Connect Site.

The one thing I have now completed is a Version of Pong using the XNA 2.0 system… is this the first one :), I do plan on using it as the test bed for my networking (I might even try and get a four sided pong going). I do plan on releasing the code to my Pong game, but for the moment it is going to be used as one of the quick games in my presentation.

Anyway off to do some more playing, remember that if you do find any bugs or have suggestions to post them onto the Connect site so that the team can look into them.

Cross Post from www.virtualrealm.com.au

RPG Music Soundtracks for your Projects

I was going through my normal morning Blog reading when I came across a great site for resources. What I found was a site offering freelance Audio Soundtrack Packs for your RPG games.

“RPG Starter Pack” from 2EastMusic provides all the music you need to start developing your own fantasy Role Playing Game. Complete with an expanding catalogue of inspiring looping mp3’s to reflect every setting, event and theme in your game from beginning to end. Each content pack comes with 5 focused tracks at a non-exclusive and royalty free license agreement, all for the affordable price of $19.95.

The packs are provided by Matthew Myers and his 2EastMusic site, all in all at the moment there are 5 RPG Starter Kits for you to Choose from. Here is a quick couple of samples for you to listen to.


Here is a Direct Link to the Store Page where the Packs are located, all payments for the packs can be done through PayPal.

Cross Post from www.virtualrealm.com.au

Call of Duty 4 Patch in the Works

The Teamxbox guys have released information on a Patch for Call of Duty 4.

Infinity Ward has announced it is already working on an update for the Xbox 360 version of Call of Duty 4: Modern Warfare.

Here are the details on the patch that have been released.

Wanted to give you a heads up for an update in the works for the Xbox 360 version. We’re going to be optimising a lot of things behind the scenes with matchmaking and host selection as well as adding a few new features via the update which I have outlined below. No ETA on when this update will be available for download, just giving a heads up on what’s to come in the future in the first potential update:
Additions / New Features:

  • Added Kill cam to Airstrike bombs and Claymores
  • Addition of Host Migration so if Host Leaves auto-chooses next best host

Tweaked the following Oldschool Mode settings based on feedback:

  • Added Unlimited Sprint
  • Increased Magazine Size
  • Added Ragdoll Cam

Optimizations / Tweaks:

  • Identify party by background colour (in Lobby)
  • Optimised server selection for first match for better connections
  • Improved network performance for 18 player games
  • Optimised ‘Chase Cam’ when Spectating
  • Fixed Playlist error when attempting to join from other games
  • Handle Corrupt Create A Class data instead of kicking player

Cross Post from www.virtualrealm.com.au

XNA 2.0 Networking and LIVE Requirements

Michael Klucher has released some more information on the Networking systems that are going to be available with the up and coming release of XNA 2.0. In the post he lists some of the main questions or scenarios and the answers to those.

One of the biggest features in the upcoming release of XNA Game Studio is the ability to create networked games over Xbox LIVE and Games for Windows® – LIVE. We thought we’d take some time to explain what you can do and what you need to do it. Before we dive into exactly what you can do with networking, let’s define a couple of commonly used terms:

  • System Link: This form of networking uses your local subnet to find and join other game sessions and can use local profiles (not Xbox LIVE gamertags) to accomplish this.
  • Xbox LIVE/Games for Windows – LIVE: This form of networking uses Xbox LIVE matchmaking to find and join other game sessions and uses your Xbox LIVE gamertag to accomplish this.

Here is a list of the common tasks that he describes in the post.

  • “I want to create a game that uses networking between my computer and my Xbox 360 console.”
  • “I want to create a game that uses networking between two of my Xbox 360 consoles.”
  • “I want to create a game that uses networking between my Xbox 360 console and my friends’ Xbox 360s consoles.”
  • “I want to create a game that uses networking between two of my Windows-based computers.”
  • “I want to create a game that uses networking between my Windows-based computer and my friend’s Windows-based computer.”

Here is the Direct Link to the Blog post on the XNA Team Blog.

Cross Post from www.virtualrealm.com.au

XNA Game Studio 2.0 Beta Coming Soon

The XNA Team have announced that we will soon be seeing a public Beta release of the XNA Game Studio 2.0 system.

“It’s been a while since we posted on the upcoming XNA Game Studio 2.0 release. The good news is that there will be a XNA Game Studio 2.0 beta available for you to download very soon!

This beta is considered “feature complete.” This means that while we still have some issues to address, all of the features that will be in the release are included as part of the beta. However like all our previous betas, the beta is for the Windows-based computer functionality only and you will not be able to deploy games to the Xbox 360 system.

Unfortunately, there were a few things that didn’t make it into this release. The most prominent being that you cannot host XNA applications in Windows Forms. All the other major features that we talked about earlier this year will be available!

Over the next few weeks, we’ll be blogging about some of the new features in XNA Game Studio 2.0 and what’s been changed. This should give you a good idea of what to expect in the release.”

Michael Klucher
Program Manager – XNA Community Game Platform

Here is a Direct Link to the XNA Teams Post.

Cross Post from www.virtualrealm.com.au

Calling all XNA Enthusiasts in Melbourne and Sydney

Come and join us for an evening with Pete Isensee from the global Microsoft XNA team. Pete is in Australia for the Game Connect Asia Pacific conference to speak about developing for the Xbox 360 and PC platforms.

Join us for an informal evening to hear Pete talk about the XNA framework, Game Studio tools and answer questions about your own XNA projects.

Admission is free but you will need to register via this Windows Live Events page.

Who should attend?

·         XNA Game Studio Express users

·         Game development and design enthusiasts

Melbourne Event Live Events Page

Date and time:
Friday, 16 November 2007
6:30 PM – 9:00 PM

Microsoft Melbourne Office
Level 5, 4 Freshwater Place, Southbank, VIC, Australia

Sydney Event Live Events Page

Date and time:
Wednesday, 14 November 2007
6:30 PM – 9:00 PM

Microsoft Sydney Office
1 Epping Rd, North Ryde, NSW 2113, Australia

Pete Isensee, Director XNA Development Connection, Microsoft

Pete is the director of the XNA Developer Connection (XDC), an engineering team specializing in game developer support, deep performance insight and technical illumination of gaming platforms like Xbox 360 and Windows Vista. XDC works with game developers and content creators worldwide to ensure titles are taking advantage of all the features and performance provided by Microsoft hardware, software and service. Before joining Microsoft in 2001, Pete was a game programmer for six years, and worked on titles ranging from casual games to massively multiplayer games. He’s been programming in C++ since 1993, focusing on templates, STL, security and optimization technology.

Cross Post from www.virtualrealm.com.au

XNA Tutorial – Fading a Splash Screen from the Distance

In my last two tutorials I went through the process of displaying a logo like splash screen for your XNA Applications. The first article went through the steps to create a base application for the tutorials and also to display a simple logo in the centre of the screen. In the second article I went through the process of making that logo fade in from nothing to a solid image.

With this third Tutorial I am going to provide you with the simple steps to have the logo fade in from the distance. To do this we are going to use the information from the two previous tutorials and then utilise the scaling of a sprite to have the image move from the distance to the main foreground.

When scaling sprites you will have to use one of the full overrides for the sprite batch draw command.

SpriteBatch.Draw(Texture2D  // Sprite Texture
 , Vector2    // Screen Position
 , Nullable<Rectangle> // Source Rectangle
 , Color     // Color Tint, Sprite Color
 , Single    // Sprite Rotation
 , Vector2    // Sprite Origin
 , Vector2 or Float  // Sprite Scale
 , SpriteEffects   // Sprite Effects
 , Single)    // Sprite Sort Depth

Adds a sprite to the batch of sprites to be rendered, specifying the texture, screen position, source rectangle, colour tint, rotation, origin, scale, effects, and sort depth.

When using the scale call we have the choice of using a Vector2 or a Float. If you choose to use the Vector2 option you have the ability to scale the sprite on one or all of the axis at different values, but if you would like to scale the sprite on a uniform manor on both axis you can specify a Float value. No mater which method you choose the values range from 0 to 1.0f, 0 meaning 0% scale or not really there, through to 1.0f being 100% scaled (or the full size of the sprite). If you did increase the value of the float it will still increase the size of the sprite, for example 2.0f would change the sprites size to 200% of the normal size.

To get the logo to scale we will need to add some globals to the code, add the following lines just underneath the fading code so that it looks like this.

float logoFadeValue; // Current Value of the Fade for the Logo
float logoFadeSpeed = 60.0f; // Speed at which the Fade will happen

float logoScaleValue; // Current Scale Value for the Logo
float logoScaleSpeed = 0.2f; // Speed of the scale operation

Next we will need to add a small section of code to the update call; this will control the rate of the scale and also stop the scale when the image has reached 100% of the scale process. Add the following lines of code at the end of the Update call just before the base.update call.

// Perform the Scale on the Logo
if (this.logoScaleValue < 1.0f)
this.logoScaleValue = this.logoScaleValue + (timeDelta * this.logoScaleSpeed);
this.logoScaleValue = 1.0f;

The final change we need to do is to change the draw call for the application. Inside the Draw call change the spritebatch.draw command so that it looks like the following line.

this.spriteBatch.Draw(this.logoTexture, this.viewportCentre,
 null, FadeColor(Color.White, this.logoFadeValue), this.logoRotationAngle, this.logoCentre,
 this.logoScaleValue, SpriteEffects.None,0.0f);

All we have done there is change the call so that we now include the scale value for the image.

When you have finished you can execute the application and see the logo fade in from the distance until it is at the very centre and solid.

Ok that does it for this tutorial, hopefully in the next one I will be going through the process of including the splash screen in the Game State sample that you can download from the Creators Web Site.

Cross Post from www.virtualrealm.com.au

Calling all Melbourne and Sydney XNA Enthusiasts

I am putting a call out to all Melbourne and Sydney Based XNA Enthusiasts or people who are interested in XNA to come forward and let yourself be known. We are in the progress of setting up a couple of events and would like to know about all who are interested.

If this is you, you can register on this site and send me a Private Message (Send Message to “Mykre”), or contact me via email (ausxna at virtualrealm.com.au). As we find out more information I will let you all know.


Glenn Wilson, (Microsoft XNA /DirectX MVP)

Cross Post from www.virtualrealm.com.au