Last active
March 31, 2021 05:28
-
-
Save patriksvensson/22791f3b413c313e80d4d77c3ff2a2a2 to your computer and use it in GitHub Desktop.
Double Buffering Console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static int _bufferHeight; | |
private static int _bufferY; | |
public static async Task Main() | |
{ | |
_bufferWidth = Console.WindowWidth; | |
_bufferHeight = Console.WindowHeight; | |
_bufferY = _bufferHeight; | |
Console.SetBufferSize(_bufferWidth, _bufferHeight * 2); | |
Draw((() => { | |
// Do your draw call here. | |
}); | |
} | |
private static async Task Draw(Action action) | |
{ | |
// TODO: Clear the back buffer here with spaces | |
Console.CursorVisible = false; | |
Console.CursorLeft = 0; | |
Console.CursorTop = _bufferY; | |
action(); | |
Console.MoveBufferArea(0, _bufferHeight, _bufferWidth, _bufferHeight, 0, 0); | |
Console.CursorLeft = 0; | |
Console.CursorTop = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment