python - Update display all at one time PyGame -
using pygame, flickering things. boxes, circles, text, flickers. can reduce increasing wait between loop, though maybe eliminate drawing screen @ once, instead of doing individually. here's simple example of happens me:
import pygame, time pygame.init() screen = pygame.display.set_mode((400, 300)) loop = "yes" while loop=="yes": screen.fill((0, 0, 0), (0, 0, 400, 300)) font = pygame.font.sysfont("calibri",40) text = font.render("texta", true,(255,255,255)) screen.blit(text,(0,0)) pygame.display.update() font = pygame.font.sysfont("calibri",20) text = font.render("begin", true,(255,255,255)) screen.blit(text,(50,50)) pygame.display.update() time.sleep(0.1)
the "begin" button flickers me. slower computer, there way reduce or eliminate flickers? in more complex things i'm working on, gets bad. thanks!
i think part of problem you're calling 'pygame.display.update()' more once. try calling once during mainloop.
some other optimizations:
- you take font creation code out of main loop speed things up
- do
loop = true
ratherloop = "yes"
- to have more consistent fps, use pygame's clock class
so...
import pygame pygame.init() screen = pygame.display.set_mode((400, 300)) loop = true # no need re-make these again each loop. font1 = pygame.font.sysfont("calibri",40) font2 = pygame.font.sysfont("calibri",20) fps = 30 clock = pygame.time.clock() while loop: screen.fill((0, 0, 0), (0, 0, 400, 300)) text = font1.render("texta", true,(255,255,255)) screen.blit(text,(0,0)) text = font2.render("begin", true,(255,255,255)) screen.blit(text,(50,50)) pygame.display.update() # call once per loop clock.tick(fps) # forces program run @ 30 fps.
Comments
Post a Comment