user705414
user705414

Reputation: 21200

Is there a way to use something like Console.write to debug in XNA code?

I am wondering how to include debug code inside the XNA? Like console.writeline

Upvotes: 7

Views: 11247

Answers (5)

Lucius
Lucius

Reputation: 3745

Enable the console.

In Visual Studio right-click your project in Solution Explorer. Then click on "Properties" and in the "Application" tab select "Console Application" as your Output-Type.

Don't forget to change it back to "Windows Application" in order to disable the console when you are done debugging.

Upvotes: 6

Juan Campa
Juan Campa

Reputation: 1231

You might want to take a look at our toolset Gearset. It is a set of tools that can help you with that. It has a dedicated window that shows you a pretty view of the output, organized by color, and provides filtering which can become quite useful when there's a lot of output.

Gearset also provides you with other tools like curve editing and real-time inspection of your objects. There's a free version and a paid version (the difference being a single feature which is unavailable in the free version). Hope it helps.

Upvotes: 1

David Jazbec
David Jazbec

Reputation: 167

For drawing text there is method spritebatch.DrawString(....) this is how i draw fps count.

     class FPS_Counter
     {
        private SpriteFont spriteFont;
        private float FPS = 0f;
        private float totalTime;
        private float displayFPS;

        public FPS_Counter(SpriteBatch batch, ContentManager content)
        {
            this.totalTime = 0f;
            this.displayFPS = 0f;
        }
        public void LoadContent(ContentManager content)
        {
            this.spriteFont = content.Load<SpriteFont>("Fonts/FPSSpriteFont");
        }
        public void DrawFpsCount(GameTime gTime,SpriteBatch batch)
        {

            float elapsed = (float)gTime.ElapsedGameTime.TotalMilliseconds;
            totalTime += elapsed;

            if (totalTime >= 1000)
            {
                displayFPS = FPS;
                FPS = 0;
                totalTime = 0;
            }
            FPS++;

            batch.DrawString(this.spriteFont, this.displayFPS.ToString() + " FPS", new Vector2(10f, 10f), Color.White);
        }

Upvotes: 1

Dmitry Polyanitsa
Dmitry Polyanitsa

Reputation: 1093

You can always use Debug.WriteLine and read your Debug messages window. Or use the tracepoints.

Upvotes: 0

Rowland Shaw
Rowland Shaw

Reputation: 38130

have you seen the Debug class in the System.Diagnostics namespace? That can send output to the debug console in VS (or an external one like DebugView)

Upvotes: 3

Related Questions