Flimmern in konsole
-
hoi
weiss jemad wie man das flmmern in der konsole wegmacht?
ich bau grad ein rpg und da muss ich immer level neuzeichnen:while(1) { system("cls"); map1(); }
wenn man das kompiliert (map1 is ne funktion wo nur cout drin ist) flimmart das so stark
kann mir jemadn helfen bitte?
-
geht nicht anders, in deinem beispiel wird die ganze zeit was ausgegeben, und dann kommt halt clearscreen. Da das so schnell geht kommt dieser Flimmereffekt zu stande. Wenn du dann nen Sleep einbaust, kannse das Problem zuminsdest nen bisschen lösen.
achja, in bestimmten Fällen ist gotoxy hilfreicher.
mfg
:xmas1: :xmas1: :xmas1:
-
Am Besten schreibst du sowas außerhalb der Konsole...
-
langeweile schrieb:
Am Besten schreibst du sowas außerhalb der Konsole...
wieso? es haben viele Leute sowas gemacht, kenn nur keine.
Gnomecoder schrieb:
geht nicht anders, in deinem beispiel wird die ganze zeit was ausgegeben, und dann kommt halt clearscreen. Da das so schnell geht kommt dieser Flimmereffekt zu stande. Wenn du dann nen Sleep einbaust, kannse das Problem zuminsdest nen bisschen lösen.
achja, in bestimmten Fällen ist gotoxy hilfreicher.kanns mir bitte den unterschied von meinem zu dem erkläre?
#include<iostream> #include <windows.h> #include <conio.h> #define tr char(176) #define n char(0) #define c char(2) #define win char(1) #define o char(219) #define t char(177) #define w char(178) #define g char(219) #define s char(30) #define e char(223) int loadmap(); using namespace std; void m_CursorCon(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } void delit(int x,int y) { m_CursorCon(x, y); cout << " "; } int goup(int x,int y) { delit(x,y); m_CursorCon(x, ++y); cout<<"x"; return y; } int godown(int x,int y) { delit(x,y); m_CursorCon(x, --y); cout<<"x"; return y; } int goright(int x,int y) { delit(x,y); m_CursorCon(++x, y); cout<<"x"; return x; } int goleft(int x,int y) { delit(x,y); m_CursorCon(--x, y); cout<<"x"; return x; } int main() { cout <<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o << endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o << endl; bool run = false; int x = 10; int y = 5; int m_nKey = 0; m_CursorCon(x, y); cout<<"x"; do { m_CursorCon(1, 15); cout << " \n"; m_CursorCon(1,15); cout << "X: "<< x << " Y: "<< y; // get key if(kbhit()) { m_nKey = getch(); } if(m_nKey == 72) { if(y >= 2) { y = godown( x, y); m_nKey=0; } else { m_nKey=0; } } else if(m_nKey == 75) { if(x <= 1) { m_nKey=0; } else { x = goleft(x , y); m_nKey=0; } } else if(m_nKey == 77) { if(x >= 28) { m_nKey=0; } else { x = goright( x, y); m_nKey=0; } } else if(m_nKey == 80) { if(y <= 8) { y = goup( x, y); m_nKey=0; } //AUSgang else if (x == 1 && y == 10 || x == 2 && y == 10 ||x == 3 && y == 10) { system("cls"); loadmap(); } else if( x == 1 && y == 9 || x == 2 && y == 9 || x ==3 && y == 9 ) { y = goup( x, y); m_nKey=0; } else { m_nKey=0; } } else { } // x = breite // y = höhe // m_CursorCon(x, y); // cout<<"x"; // Sleep(500); // delit(x,y); /* y = goup( x, y); x = goright( x, y); y = godown( x, y); x = goleft(x , y);*/ //m_CursorCon(x, y); //cout<<" "; }while(!run); } int loadmap() { cout <<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o << endl; cout <<o<<" "<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<< o<<endl; cout <<o<<" "<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o<<o << endl; bool run = false; int m_nKey = 0; int x = 1; int y = 8; m_CursorCon(x, y); cout<<"x"; do { m_CursorCon(1, 15); cout << " \n"; m_CursorCon(1,15); cout << "X: "<< x << " Y: "<< y; // get key if(kbhit()) { m_nKey = getch(); } if(m_nKey == 72) { if(y >= 2) { y = godown( x, y); m_nKey=0; } else { m_nKey=0; } } else if(m_nKey == 75) { if(x <= 1) { m_nKey=0; } else { x = goleft(x , y); m_nKey=0; } } else if(m_nKey == 77) { if(x >= 28) { m_nKey=0; } else { x = goright( x, y); m_nKey=0; } } else if(m_nKey == 80) { if(y <= 8) { y = goup( x, y); m_nKey=0; } else if( x == 1 && y == 9 || x == 2 && y == 9 || x ==3 && y == 9 ) { y = goup( x, y); m_nKey=0; } else { m_nKey=0; } } else { } }while(!run); }
hab ich auf game deception von P47R1CK gefunden.
also ich sehe nichts das das flimmern wegmacht
-
weiss keiner was?
-
bitte nur eine antwort genügt ich mochte es richtig habn
-
Flllll62 schrieb:
langeweile schrieb:
Am Besten schreibst du sowas außerhalb der Konsole...
wieso? es haben viele Leute sowas gemacht, kenn nur keine.
Ja, unter DOS ging das auch recht gut...
Oder unter Linux via Ncurses...
-
aber wie geht das?
-
Das Flimmern bekommst du weg, indem du mit mehreren Screenbuffern arbeitest. Guckst du dazu in der MSDN:
SetConsoleScreenBuffer
SetActiveConsoleScreenBuffer (oder irgendwie so)Alternativ nach 'Console Functions' suchen.
Während du also in den einen Screenbuffer Daten schreibst, gibst du den anderen aus, der schon vorher befüllt wurde. So machen das auch die Bibliotheken caca, etc. Klappt ganz gut.