XNA Creators Club Online
Page 1 of 1 (11 items)
Sort Posts: Previous Next

Debugging? Any way to show stuff on the screen?

Last post 24/10/2009 23:20 by Shadowless. 10 replies.
  • 22/10/2009 5:29

    Debugging? Any way to show stuff on the screen?

    Hi,

    Mostly when I want to know values of some variables, I can't put breakpoints since it would break on alot of not important occasions before hitting it for the right time (and I vaguely remember putting IF's for it, but I donno how anymore). So I used Trace.WriteLine (or something like that) but that required me to ALT+TAB my way alot and wasn't that useful. So I was after a cheap (performance wise) way to show some values on the screen to ease the debugging. I'm sure there is something there in XNA for such matter.

    Thanks you guys in advance.
    Try not. Do, or do not. There is no try.
  • 22/10/2009 5:55 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    You can just use the build in .NET namespace System.Diagnostics

    System.Diagnostics.Debug.WriteLine("Debug Info"); 

    When you are running in Visual Studio, all that debug information will show up in the output window.
    Just make sure that your game window is smaller than your screen resolution, so you don't have to switch between VS and your game.

    Otherwise you can also write something to the screen with the spritebatch:

    spriteBatch.DrawString( Font1, output, FontPos, Color.LightGreen, 0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f ); 


  • 22/10/2009 13:58 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    Hi,

    Can you please help with Font? I'm facing difficulties using a font, I use SpriteFont and Content.Load<SpriteFont> to load a font but it doesn't find my font to load.
    Try not. Do, or do not. There is no try.
  • 22/10/2009 15:55 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 23/10/2009 4:04 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    Jim Perry:


    Thanks alot man, darn I was missing to address the folder to the naming, I just thought as of C++, those folders are for management and doesn't need to be addressed via code.

    Back to teh topic, I'm currently writing stuff that I want from the Draw section of my class code but that method is called once per frame and is called after everything else. What I want is being able to call to draw my stuff from everywhere I want, like how you can use Trace command. I want to see my values on the screen from various places, not just Draw method.

    What do you suggest on that?
    Try not. Do, or do not. There is no try.
  • 23/10/2009 4:49 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    How about using a Queue, recording where and when the item in the Queue occurred, and drawing the items in the Draw method.
    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 23/10/2009 4:58 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    Jim Perry:
    How about using a Queue, recording where and when the item in the Queue occurred, and drawing the items in the Draw method.


    I think I would lose data. If I understood your point correctly, when I enque my i.e. UpLeft position to draw on the screen, there is no guarantee that until the Draw calls, the data remains the same.
    Try not. Do, or do not. There is no try.
  • 23/10/2009 5:04 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    99% of the time it'll still be the same unless you're doing something really weird. Maybe I just don't understand what problem you're trying to solve. If you log the data, you'll see it change values.
    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 23/10/2009 5:28 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    Jim Perry:
    99% of the time it'll still be the same unless you're doing something really weird. Maybe I just don't understand what problem you're trying to solve. If you log the data, you'll see it change values.


    The problem is like this, I have a collision detection method that is called four times per frame and I want to see values of variables that are used in this collision detection function on the screen. If I just put the values on the screen in Draw() call, it will print out my variable's latest value and I will miss the value it had the three times it was used, since it's called once per frame and my values obviously have their last values.

    I hope I'm clearing myself up.

    I've seen this in big games developers too, they have alot of small data that is always on the screen (I think they call it profiling or something) to check most important values.
    Try not. Do, or do not. There is no try.
  • 23/10/2009 8:41 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    If you use Jim's method, it doesn't matter how many times your collision detection is called because each time it is called it queues it's current values, so the previous values are still there in the queue, and don't get cleared until your Draw routine dequeues everything when drawing, which is once a frame.

    A Queue, a Stack, a List (which is cleared each frame) all would work perfectly well. I personally use a List and clear it at the beginning of my Update.


    #tip: Wrap all your code that adds debug info to the queue in a #DISPLAYDEBUG definition because they can generate a lot of garbage.
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 24/10/2009 23:20 In reply to

    Re: Debugging? Any way to show stuff on the screen?

    test84:
    Jim Perry:
    How about using a Queue, recording where and when the item in the Queue occurred, and drawing the items in the Draw method.


    I think I would lose data. If I understood your point correctly, when I enque my i.e. UpLeft position to draw on the screen, there is no guarantee that until the Draw calls, the data remains the same.

    Actually, in such a style of logging via a queue, you should not put a reference to the data on the queue (which is what I think you think you should do.) You should convert the data you want logged to a string (this obviously captures the value exactly when you want it) and put the string on the queue. You can also add other information (e.g current time, a full call-stack, whatever) to the queued string.

    This kind of "deferred" logging has many advantages (performance, simplicity) but it may have a few shortcomings (depending on whether you need the particular features or not.) For example, if you break the execution of your program in the middle of a frame (before the draw call) you obviously won't see the logged data. One solution is to use other methods of logging too, for example, call the Trace.WriteLine as soon as you push something on the queue.
Page 1 of 1 (11 items) Previous Next