python - Pygame, Draw the same frame for a set amount of time -


i want display message 2 seconds.

the logic im using right making code wait using pygame.time.delay(2000) after pygame.display.flip.

a short example: (i use flip-delay on my code lot)

    write_gui("{0} has appeared".format(monster.name), blue, 24, text_corner_x, text_corner_y)     pygame.display.flip()     pygame.time.delay(2000) 

this work tends "hang" entire process, when happens bugs because of this, frame loss because program can keep sleep-awake cycle.

so i'm thinking right draw same frame 2 seconds.

so guys recommend should do?

because 1 of answers put every flip on while loop, there has better line-conservative approach solve this.

your program "hangs" because not calling pygame.event.get() when sleeping, pygame.event.get()lets pygame handle internal events.

the simplest way solve use return value dt = clock.tick(), in case dtwill time since last call clock.tick(), value in milliseconds. use value increment counter on how long show message.

you write function if wanted , call how long wait:

def waitfor(waittime): # waittime in milliseconds     screencopy = screen.copy()     waitcount = 0     while waitcount < waittime:         dt = clock.tick(60) # 60 fps here         waitcount += dt         pygame.event.pump() # tells pygame handle it's event, instead of pygame.event.get()         screen.blit(screencopy, (0,0))         pygame.display.flip() 

this function wait specified time , keep screen before call.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -