| anthony62490 (2) | |||||
|
For school, I decided to simulate Conway's Game of Life. Things went very smoothly until I decided that the game needed to be in color. Using information found on this board (post #3), http://www.cplusplus.com/forum/beginner/5830/ I was able to add a different color to each generation of cells The problem I am having is that output is occurring too slowly. Whereas before, I would append all of the cells together into one big string, now I am forced to print each cell individually. This causes the display to flicker horribly at high speeds.
My question is, is there any way to store every cell along with its corresponding color and print them to the screen all at the same time? How would YOU solve a problem like this? | |||||
|
|
|||||
| firedraco (5494) | |
| Honestly, I would just not use color on the console and instead use a graphics lib like SFML or something to do it. It wouldn't be that hard, really. | |
|
|
|
| DTSCode (27) | |
| What os are you using? becuase each has its own way | |
|
|
|
| L B (3806) | |
|
@DTSCode Judging by the Windows API calls in his code, he could be using any OS - I'll just guess he's on a *nix platform. Sorry if you're not familiar with Windows API function names. I'll have to agree with firedraco - at this point you should abandon the console and use a graphics library. Printing everything "at the same time" won't speed it up any or reduce flickering - it's the console for Stroustrup's sake. | |
|
Last edited on
|
|
| coder777 (2549) | |
|
take a look at this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682088%28v=vs.85%29.aspx you can write into a buffer and make it active | |
|
|
|
| DTSCode (27) | |
| sorry my mistake i didnt look at the code which now that I think about it wasn't posted originally. (S?)He edited it so before I thought it was just printing in colors | |
|
|
|
| L B (3806) | |
|
You may have skimmed it, because the OP has not been edited. Look at the bottom of this post, which has, and then look at the bottom of the OP. (Just for future reference, I'm not heckling you) | |
|
Last edited on
|
|
| DTSCode (27) | |
| yeah i understand. thanks. i must have been more tired than i thought this morning and missed it. | |
|
|
|
| anthony62490 (2) | |||||
| |||||
|
|
|||||
| tntxtnt (83) | |||
so at each stage do all cells have same age, or same color? If so, you can simply SetConsoleTextAttribute with the cellAge color before outputting the boardString.
if each cell has different colors then... don't color them or use a graphics lib instead (: | |||
|
|
|||
| DTSCode (27) | |
| correct me if im wrong, but isn't that all win32 code? so it can't be portable | |
|
|
|