pygame 在循环 150 左右冻结在此循环中。循环继续,但 pygame 停止更新这是我的代码:
import pygame
from cv2 import imread # the only one needed! (to get image size) could of used pygame though...
image = imread("frame0.jpg") # get the first frame to get size of framed video
h, w, channels = image.shape
screen = pygame.display.set_mode((w,h)) # define the surface
c = pygame.time.Clock()
for i in range(0,4099): # i know this is VERY inefficent... start frame - end frame
im = pygame.image.load("./frame%d.jpg" % i) #load frame
screen.blit(im, [0, 0]) # put the image on the surface
pygame.display.update() # update time! where you've been?
screen.fill((0,0,0)) # delete canvas after update the events can be below due to the update occuring next cycle
print(i) # debug
del im # delete image variable (not necessary)
c.tick(30) # tick the clock! tick tock!!
print("done!")
所以这段代码应该做的是在一个文件夹中播放一系列图像。但 pygame 冻结,循环继续。这是一个for循环。这是我的更新方法吗?有没有办法来解决这个问题?
另外,如果我将帧速率降低到 10 左右,同样的事情也会发生在同一帧。有限制pygame.display.update()
吗?