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()
是否有限制?