Debugging Tips for XNA Projects
- Use the PC version of the project, rather than the XBox version, so that
you've got everything on one computer
Unless otherwise specified below, everything listed will work on the XBox
(Since XNA GSE can remotely debug the code that's on the XBox), but it may be
easier, quicker, and more comfortable to debug the game all on one PC, in the
way that most people are used to debugging other programs)
- If you do use an XBox project, you can use the debugger, even on the XBox
game (press 'F5' to deploy to XBox, with the debugger attached - you can set
breakpoints, etc, etc on the PC, and the code will run on the XBox, and when
the code (on the XBox) hits the breakpoint, the program will freeze, and
you'll be dropped into the debugger on the PC)
How do you get around the fact that the update loop will run 200 times before
it hits the time that you're interested in?
- Conditional breakpoints
- System.Diagnostics.Debug / Trace
Can be disabled using #undef DEBUG / TRACE
The output will appear in VS's 'Output' window, so you can do 'printf' style
debugging. If you call this for every update,you will get a _lot_ of
messages, though!
I'm trying to visually confirm that the game does what I want it to, but it
goes too fast
- IDEA: Implement a 'Slow Mode':
Downside: If you have a
Add to your game class:
private
static
bool m_slowMode =
false;
private
static
int m_slowModeCount = 0;
private
static
int m_slowModeTarget =
10;
public
static
bool SlowMode
{
get {
return m_slowMode; }
set { m_slowMode =
value;
if (m_slowMode)
m_slowModeCount = 0; }
}
Add to UpdateWorld (at the very top)
// SLOW MODE: only
move once every X updates
if
(SlowMode)
{
if
(m_slowModeCount++ < m_slowModeTarget)
return;
else
m_slowModeCount = 0;
}
General Programming Tips:
- You'll continually get the 'button pressed' status when the button is
down, and the 'button released' status when it's not being pushed.
you'll need to use a boolean (or something similar) in order to track the
status, and only react once the button has been pressed AND THEN RELEASED
- You'll need to implement a timer (using TimeSpan) so that you don't get a
zillion 'autokeys' for things like holding down DPad keys