I'm writing a python curses game (https://github.com/pankshok/xoinvader). I found a problem: in terminal emulator it works fine, but in tty screen blinks. I tried to use curses.flash(), but it got even worse.
for example, screen field:
self.screen = curses.newwin(80, 24, 0, 0)
Main loop:
def loop(self):
while True:
self.events()
self.update()
self.render()
render: (https://github.com/pankshok/xoinvader/blob/master/xoi.py#L175)
self.screen.clear()
#draw some characters
self.screen.refresh()
time.sleep(0.03)
Constant time in sleep function is temporary, until I write 60 render calls controller.
How to implement render method correctly?
Thanks in advance, Paul.
Don't call clear
to clear the screen, use erase
instead. Using clear
sets a flag so that when you call refresh
the first thing it does is clear the screen of the terminal. This is what is causing the terminal's screen to appear to blink. The user sees the old screen, then a completely blank screen, then your new screen. If you use erase
then it will instead modify the old screen to look like the new one.
You may still see some odd flashing or other artifacts on slow terminals. Try calling screen.idcok(False)
and screen.idlok(False)
to stop curses from using insert and deletion operations to update the screen.