I use the console.out.writeline() to print the coordinates belonging to the different sprites in a XNA game. But after a few seconds, the game starts to go really slow, and almost stop.
(When not writing to the console, there are no problems with performance).
(The sprite's positions are written in every update method)
Is there a way to write to the console without destroying the performance to the game?
Are you able to write to a log file instead of the console? That may well be faster due to buffering and the lack of scrolling, displaying etc.
Do you actually have a console up while this is running? If so, try minimising it when you're not interested. My guess is it's the scrolling which is causing the problem.
EDIT: Okay, it seems some evidence is in order.
A few tests... I don't have XNA installed, but different ways of writing to consoles are still interesting. I wrote the numbers 0-99999 to various consoles:
So as you can see, the Visual Studio console is painfully slow, a non-minimised "normal" console is next slowest, a minimised console is reasonably nippy, and writing to a file is very quick.
I stand by my advice to try writing to a file instead of the console, and otherwise if it's a standalone console, try to minimise it for most of the time.
"Is there a way to write to the console without destroying the performance to the game?"
Well, you could create your own ingame console like most game engines do (most notably Quake), and display the console when a key is pressed.
Edit:
if you don't want to implement your own console, there is a project doing this:
http://www.codeplex.com/XnaConsole
which has advantages over the Win32 console, because it runs in game, at game framerate, and won't make you loose your device when switching between the console and your xna app. (Although device recovery is automatic in XNA, loosing the device still happens under the covers)
It is likely that you are writing too much data to the console. Reduce the frequency of console writes by using a counter or a timer. One update per second is usually enough to see what you need.
I know this is an old post, but for those with similar questions there is a better way. There is another console-type library you can include that is really easy to use (a lot easier than the xna console project). It is called XNA Debug Terminal and it can be found at http://www.protohacks.net/xna_debug_terminal
This puts a terminal like command window on top of your game and allows you to view/set the value of any variable, invoke any method, or even watch values change in real time. It is completely open source and works with XNA 3.0 and XNA 3.1. This can easily allow you to see your sprite coordinates (or anything else) at any time during your game execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With