Reelix's Site Of Stuff

XNA

All info herein deals with XNA 4.0

  XNA MediaPlayer Class annoyance
Trying to add music into my game, I came across the annoying error:

"Song playback failed. Please verify that the song is not DRM protected. DRM protected songs are not supported for creator games."

Turns out, this happens if your Windows Media Player is corrupt (Or simply uninstalled)
Meh >_<

Note: It IS possible to use SoundEffect instead of MediaPlayer.
Your first compile will take a lot longer (It will freeze, just wait), and the audio file will be converted to something 10x its size, but it will work...
An alternative is using the FMod sound library (It's a +- 250kb DLL, but if you don't want WMP required, and a small size, it's the only alternative)
Many commercial games use it, so don't feel bad about using it too :D
 
  An annoying XNA bug when mixing 2D / 3D
When loading a 3D model in XNA, and using spriteBatch, your model becomes a bit... broken
In my case the Goblin was a 3D Model, and the cursor was done using spriteBatch:

Broken 2D 3D

To fix this, add the following lines of code to the top of your Draw Method:

// 3 Lines to fix the annoying glitch before drawing
graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend;
graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
graphics.GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

Your image will look fine once again!

Fixed 2D / 3D
 
Copyright Reelix© 2012!