SetConsoleTextAttribute
Oct 14, 2012 at 2:44am UTC
Hello,
I am trying to set some text color in my console dungeon crawler. However, when I attempt to display the map, after about 6 times the Text color fills the entire column width of the console, at only the position where the map would be.
Here is my PrintMap code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//prints the map, with the current position as an x
void PrintVisitedAreas(int cx, int cy)
{
string line;
if (cx <= 10 || cx > 0 || cy <= 10 || cy > 0)
myVisitedAreas[cx][cy] = 'X' ;
SetTextColor(TC_TEXT);
cout<<endl<<"Map of Tovashal Dungeon." <<endl;
cout<<"Key:" <<endl;
cout<<"O = Visited Area" <<endl;
cout<<"X = Current Location" <<endl;
SetTextColor(TC_MAP);
cout<<"\n" <<endl;//------------"<<endl;
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10 ; y++)
{
line += myVisitedAreas[x][y];
}
cout<<line.c_str()<<endl;
line.clear();
}
cout<<endl;//"------------"<<endl;
myVisitedAreas[cx][cy] = 'O' ;
SetTextColor(TC_TEXT);
};
and the SetTextColor() function:
1 2 3 4 5 6 7
void SetTextColor(TEXT_COLOR Color)
{
static HANDLE ConsoleHandle = 0;
ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(ConsoleHandle, Color);
};
Is this a buffer issue? I don't have any other problems, just that it fills the entire column width with the background color.
Thanks for any help that you can provide.
Topic archived. No new replies allowed.