when i use system("cls") in my game it takes way too much time to re-draw the screen! is there anyway to speed this up? in harryP's maze game this is not wrong!
Printable View
when i use system("cls") in my game it takes way too much time to re-draw the screen! is there anyway to speed this up? in harryP's maze game this is not wrong!
Clearing the screen is in the FAQ. In short, check your compiler documentation for a local cls function.
i dont have a documentation, is there one for Dev-C++ or MingW or whatever?
my source is this
but that works as well as system("cls"); !Code:#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
using namespace std;
void clrscr(void)
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '),
dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
int main(void)
{
// configure the main console
SetConsoleTitle("Engine Text v0.1");
// start game loop
int play = 1;
int playerX = 10;
int playerY = 10;
while (play)
{
// :: this is the inner-game code
// draw the board outline
cout<<"############################################"<<endl;
cout<<"############################################"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"#### ####"<<endl;
cout<<"############################################"<<endl;
cout<<"############################################"<<endl;
// redraw and clear
clrscr();
}
system("PAUSE");
return 0;
}
so im lost. :confused:
go to www.mingw.org..Quote:
Originally posted by CammoDude91
i dont have a documentation, is there one for Dev-C++ or MingW or whatever?
so im lost. :confused:
there should be a link to the documentation there.
You could also make a function for it. This one probably wouldn't help any if system("cls") isn't working for you because it involves a loop and all, which just takes away more from the speed. But, you could try this.
Good luck with all this. I don't know if that'll help or not, but it's always worth a go.Code:#include <windows.>
#include <stdio.h>
#define MAX_WINDOW_X 79
#define MAX_WINDOW_Y 24
void gotoxy(int x, int y) // A function to place the cursor at x,y
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
void ClearScreen()
{
for(int i=0; i < MAX_WINDOW_Y; i++)
{
for(int j=0; j < MAX_WINDOW_X; j++)
{
gotoxy(j,i);
printf(" ");
}
printf("\n");
}
gotoxy(0,0); // This resets the cursor back to 0,0
}
Brendan
I wouldn't name my function clrscr() either, because that's already defined by a few compilers...
Why not just output 25 newlines, and let the screen scroll down?Quote:
Originally posted by harryP
You could also make a function for it. This one probably wouldn't help any if system("cls") isn't working for you because it involves a loop and all, which just takes away more from the speed. But, you could try this.
//...
Good luck with all this. I don't know if that'll help or not, but it's always worth a go.
Brendan
nothing here works. i asume it is just a diff function for mingW32 but i cant fund any FUNCTIONS in the doc at mingw.org.
:confused:
Hey, this is harryP, but I'm on a different computer.
Yeah, Salem brought up a good point. You don't need to clear the screen everytime the player moves (assuming I'm understanding this correctly). Just re-draw the player, that'll make things much smoother. For example, if the player was at 10,10 and the user decided to make him go up, just re-draw the player at 10,9 and erase the player at 10,10.
That'll work much better for you. The only time I used a clear screen function in my maze thing was when a new maze was being loaded or I was showing the menu or something. You'll find that it moves much faster :)Code:void UpdatePlayer(int direction, int &x, int &y)
{
// Move the player up
switch(direction)
case 1:
gotoxy(x,y); // Go to the player's original position
printf(" "); // Erase him (If this was being stored in an array, you'd want to update the array as well, like map[x][y] = 0 or something
y++; // Update the coordinates
gotoxy(x,y);
printf("%"); // Or whatever your player looks like
// Again, if you're using an array, you'd need to update that, too
break;
...
}
Brendan
thx man - i think i got it from here. :)
You could do this in assembler if Windows will let you access the video memory directly. But you need the location of the video memory for the mode you are in - text modes are completely different beasties than graphics modes, but it can be done.
I'm fairly sure that you can do this because Windows will allow you to access the video RAM for graphics modes. But absolutely no one has posted anything about this in all of the console mode clear screen questions so I might be wrong.
Personally I feel that using printf() to clear the screen is archaic and slow, but that might be your only choice.