Tag Archives: XNA

The end of XNA?

If you are just starting with XNA game development, than you should probably read this post before you invest too much time in XNA.

Mind, this is no official statement from Microsoft, so there is still hope, but i agree with Promit. It is most likely, that we never see another big XNA update.


Read here: http://ventspace.wordpress.com/2011/11/28/directx-and-xna-status-report/

Implementing a level of Detail (LoD) system in XNA games

If you have big levels and/or a huge amount of 3d models you have to render you will find that the game gets slower and slower.

Before you try to  optimize the draw codes, please use a profiler to make sure, that the problem is not somewhere else. Maybe the update logic is the problem?

You have some ways to tackle the problem:

  1. optimize everything in your draw code and shaders
  2. tell the user to buy a better computer
  3. remove objects
  4. lower the quality of models

Or you could scale the quality with the power of the computer displaying them.

To do so in a quick (and a bit dirty) way go to your class that holds the model and decides which model is to render (might be only one there without a LoD system or damage system).

  • Add a second and third model.
  • Make low poly versions of your model. One really low and one somewhere around the quality you can life with.
  • Load these lower versions of the model in your class
  • Add some code to check the distance to the camera
  • Now simply make some if statements:
    • If(distance >500.0f) do nothing
    • If(distance > 300.0f) draw(lowest_quality_model)
    • If(distance > 100.0f) draw(average_quality_model)
    • else draw (high_quality_model)
  • Play around till the numbers make sense in your game.
  • You might also add a condition that a slow running game never renders the highest_quality_model
  • As my LoD system not only draws the model but the shadows too i could use the lowest quality model to draw the shadow.
  • I also added a condition that the game fist tries to stop drawing shadows and than lowers the quality of models even further till the point where only the lowest poly models really close to the camera a drawn and the rest is ignored.
  • Be carefull with drastic measures. It is not always good to lower the overall quality of models just because the game missed one or two frames somewhere. The problem might not be the draw code at all.

Hope this helps you.

Workshop: Windows Phone 7 Game Development Lesson 3 coming up next week

We will display some 2D stuff and move it around.

The type ‘Microsoft.Xna.Framework.Matrix’ is defined in an assembly that is not referenced.

Possible reasons and fixes for the error message:

The type ‘Microsoft.Xna.Framework.Matrix’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘Microsoft.Xna.Framework, Version=, Culture=neutral…

  1. You have references to different Versions of Microsoft.Xna.Framework in your projects. happens easily if you are like me and just import a library project and do not check the XNA version it was built against.
  2. Classic, you use some cool third party dll and they managed to build it against everything but your XNA version. … but tell you they did on the website. Thanks for that again.
  3. Content Pipeline Projects are alway, yes really, executed on the PC. Never set Visual Studio to build them for target platform Xbox360 or any CPU. You need x86. Sometimes this is changed automatically… aka you did something stupid and didn’t realise it.
  4. A C# class library doesn’t do so well as Xbox360 game library. Check your project types and settings.
  5. As a last resort. Throw all references out and set them new to one specific dll version and rebuild everything. Check where the error occurs and go from there on.

Hope this saves you some sleepless hours.

How to Display Text in your XNA Windows Phone 7 game

First thing you need to do is add a SpriteFont object to your code.

Done like this: SpriteFont myFont (or whatever name you want to give it).

SpriteFont mySpriteFont

Add SpriteFont

Next you need an actual font you can load. For that you go to your solution explorer and right click your content project. Select add -> new item -> SpriteFont.

Add new item

Add SpriteFont to content project

Maybe you should select a better name, that the default one. But it doesn’t really matter much.

Select SpriteFont

Add SpriteFont

You can edit how your font looks like in the .spritefont file. It is a XML like format. Most stuff you find in there should be pretty much self-explanatory. At the bottom you find tags specifying a character region. Please note, that not all fonts can display all characters. If you happen onto a bug resulting from some character display problem or exception, have a look here, if your font can display all your characters. The rest describes size, text decoration and stuff.

spritefont file

The font description

For this post, I leave everything like it is and go on to actually displaying something on the phone.

First we need to load our SpriteFont1 in the ContentLoad()-method of our game class.

myFont = Content.Load("SpriteFont1")

All we have to do is display some text now.

We go to the Draw-method and beginn the spriteBatch draw with SpriteBatch.Begin().  The spriteBatch-Class offers us a DrawString-mehtod we use to display text. It first parameter is our SpriteFont. The secont the String you wish to display. This could of course come out of some Sting variable. The third is the position of the text on the screen and the last one, the color in the text is drawn in. We complete this with a spriteBatch.End() in the next line.

And see the result here: I made the Font bigger and red for this example. The size is controlled in the .spritefont file, the color can be selected in the DrawString-method.

Text on WP7 emulator

%d bloggers like this: