views:

167

answers:

3

I'm messing around with game loops and going to create some games as practice.

Currently I have a steady game loop up where the game is updated as fast as possible and the rendering is updated x times a second (25 currently)

The rendinging method is basically a draw + Console.Clear() and at very high updates the display becomes very jittery since it's not finished drawing when Console.Clear() hits.

Is there a better way of doing something like this?

Can I write whatever data to the console and then replace it with some other data?

+3  A: 

Since you're in C# anyway, you might want to look into the XNA Framework.

I'm guessing your problem arises from Console.Clear() not being optimized for this kind of use, as XNA uses a similar method (Clear() is called on a GraphicsDevice).

If you don't want to try using XNA, then it may possibly be faster to draw a rectangle (solid black or gray or whatever) rather than call Clear() to 'blank' out the screen and then draw over it.

Zwergner
I'm starting with a console to understand the basics inner workings of a game loop. But it could be faster to draw a blank slate over the data instead of the Console.Clear().
Ólafur Waage
+1  A: 

You migth wanna check out the ConsoleLibrary

I didn't use it, but from the article/demos it seems it would allow you to do bunch of neat stuff on the console.

Michał Piaskowski
+4  A: 

Assuming you Write a full screen from topleft again in every loop you could simply replace the Clear() with:

 Console.SetCursorPosition(0, 0);

And overwrite the previous screen.

Henk Holterman
Ahh that might be the key to what I am experiencing. Thanks :)
Ólafur Waage