0

I want to make small animation in a c++ console application. I move only one character so system("cls") and print out the changed string. This takes a long time and is unnecessary for moving one character so i was wondering if there is a function that lets you manually change the character at a certain location. I would prefer a cross platform option but i doubt there is one so if you could provide Linux and Windows or just Windows that's fine.

I have a method to clear the console and re-print everything after changing the position of the character but it is quite unpleasant to watch.

for (int x = 0; x < 15; x++) {
    system("cls");
    print_galaxy_with_spaceship(galaxies.at(0), player);
    player.move(x, 0);
    sleep(10);
}

I want a smooth changing of characters to show movement but there is a clear distortion when watching the characters re-print.

  • Is there a reason to do it in a console window? – Michael Chourdakis Jan 06 '19 at 01:04
  • @Michael I am starting out in c++ and cross-platform gui application require a third-party api and i am not well versed enough in c++ for more advanced projects like that so i am taking advantage of the console which both Windows and Linux have – Java Freshman Jan 06 '19 at 01:08
  • 3
    There is no way to do this with the standard library, but there are 3rd party libraries for it, such as ncurses. – Remy Lebeau Jan 06 '19 at 01:09
  • Eventually you will abanton this process, because cross platform gui between Windows and Linux is a failed business, you would only lose time struggling to achieve cross platform stuff with toolkits like Qt. The proper way is to use Direct2D to do it in Windows. Complete your C++ classes, then go for Windows when it is for gui, go to Linux if it is for server stuff, etc. – Michael Chourdakis Jan 06 '19 at 01:10
  • @Michael I prefer Linux over Windows but most PCs and applications run on Windows but i don't like the native gui api for Windows but i know i will abandon this process, but currently im going to use it and out of interest i ask this question not necessity. – Java Freshman Jan 06 '19 at 01:13
  • Well, you have to like it, or you will never make anything competitive in Windows. If you prefer linux, stick to it. Trying to achieve gui-level cross platform *will* fail. – Michael Chourdakis Jan 06 '19 at 01:14
  • @RemyLebeau Looks interesting i will check it out thanks – Java Freshman Jan 06 '19 at 01:15
  • @Michael I know but i am probably going to stick to low level logic with c++ i am just doing this project as practice but thanks for the help – Java Freshman Jan 06 '19 at 01:20
  • [curses for different platforms](https://stackoverflow.com/questions/53839971/how-and-whether-to-colorize-text-without-ncurses/53848104#53848104https://stackoverflow.com/questions/53839971/how-and-whether-to-colorize-text-without-ncurses/53848104#53848104) – Ted Lyngmo Jan 06 '19 at 04:35

0 Answers0