Common mistakes when using XNA

Just wanted to spend a few minutes on some regular questions I get.
1: SpriteBatch and SaveState
First of all, the SaveState on the sprite batch.
When you are using the Begin() method of the SpriteBatch class, it will set some of the render/device states to different values. Once you call the End() method of the SpriteBatch object, the render states will not, by default, be restored. This can result in some wierd artifacts that makes your 3D models( if you render 3D and 2D ) look wierd, especially considering the UV-coordinates.
This can lead to a lot of frustration, but luckily, the solution to this is pretty simple:


SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
new Rectangle(0, 0, 200, 200), Color.White);

Here we use the SaveStateMode.SaveState to sve the state of our device. Once we call End(), the state that was saved in Begin will be restored!
2: AudioEngine, playing music is randomly crashing!??
Just got one comment on this one. Did you remember to update your AudioEngine instance? Say your instance is named audio, this problem can most of the time be solved by just calling this function from your Update loop:
I will update this post with more soon!
This entry was posted in XNA. Bookmark the permalink.

1 Response to Common mistakes when using XNA

  1. Laura Marie Cruz says:

    Cool, maybe you can make your own FAQ thing? Probably loads of those.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.