Flickering and the windows console

Started by
1 comment, last by Skeleton_V@T 18 years, 3 months ago
A while ago, I made a memory game program which uses ascii graphics to represent the cards. Everything works fine but I notice that there tends to be a bit of flickering whenever the user finished picking the cards and the program redraws everything again. How do you eliminate this? Oh I am programming in C and using the Dev c++ IDE and the windows console api.
How about them apples?
Advertisement
I don't believe that there is a way to solve it except to utilize an actual graphics library which allows for double buffering and text output (or you could alternatively write your own text functions or get a text library)

SDL, OpenGL, DirectX all allow frame buffers.

Your flickering issue comes from the text being updated while the screen is refreshing and before the whole scene is ready to be shown. Double buffering can fix this by first setting up the pixels to draw and then flipping the screen only when ready to display.

It could also be (and this is a related problem) due to your clearscreen function simply pushing the text off the screen as opposed to actually clearing the screen properly.

My reccomondation would be SDL for an ascii game because of it's simplicity and input/sound functionality.
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
For single buffer you should redraw only necessary pixels. When the card is moved, you fill the old rectangle with the background, everything outside that rectangle won't need redrawing. The flickering shouldn't appear anymore but it requires a little bit more work. You can archive this by masking.

A better alternative: Windows provides a number of function that support block reading and writing. You may simulate the effect of double buffering by having a second console screen buffer. When drawing, you provide that buffer pointer to WriteConsoleOutput () or WriteConsoleOutputCharacter ().

Better yet, GameTutorials has quite a few tutorials on 2D games using console and Win32 drawing routines, you may take a look at that site.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--

This topic is closed to new replies.

Advertisement