I want to render my 2D semi_text-based game scene, in the console (cmd) as my frame output ...
I did it by printing a 2D-array of simple character that present my game world. ( like "-" and "|" )
but each frame ( = each loop ) I want to clear screen to repaint my matrix . and now I use system("cls") ... But It's too slow ! Here is my render function :
void Engine::engineRender()
{
system("cls");
// Render Background
for(int i=0; i<10 ; i++ )
{
for ( int j=0 ; j<40 ; j++ )
{
printf("%c",map[i][j]);
if((int)(player1->yPos)==i && (int)(player1->xPos)==j )
printf("\b&");
}
printf("\n");
}
}
And my Main Game loop is this :
while(true)
{
_ftime(&cur);
elapsMili += (cur.time - last.time)*1000 + (cur.millitm - last.millitm) ;
if ( elapsMili >= 1000/frameRate ){
elapsMili -= 1000/frameRate ;
last=cur;
needRender = true ;
}
engineUpdate();
if (needRender){
engineRender();
needRender=false;
}
}
any idea to have more smooth render ?
You could try a little library I made just for this purpose (fast smooth console rendering). It should be pretty straightforward to use. It works only on windows though.