为什么 pygame.display.update 在被调用一定次数后停止工作?
why does pygame.display.update stop working after being called a set number of times?
当 运行 我正在将一些文本 blit'ing 到我的表面 (WIN) 并且我希望在游戏中显示它所以我调用 pygame.display.update 来更新显示,这非常有效很好,直到循环迭代了大约 75 次,此后显示停止更新。下面的代码
def dialogue(x,y,text):
global clock
global run
typing=True
tempstring=""
counter=0
switcher=0
for z in range(0,(len(text))):
clock.tick(15)
tempstring=text[0:z+1]
counter+=1
print(counter)
print("temp is "+tempstring)
writing=TITLE_FONT.render(tempstring, 1, (255,255,255),(0,0,0))
if x==-1 and y>-1:
pygame.display.update(WIN.blit(writing, (640-(writing.get_width()//2),y-(writing.get_height()//2))))
elif x>-1 and y==-1:
pygame.display.update(WIN.blit(writing, (x-(writing.get_width()//2),360-(writing.get_height()//2))))
elif x==-1 and y==-1:
pygame.display.update(WIN.blit(writing, (640-(writing.get_width()//2),360-(writing.get_height()//2))))
else:
pygame.display.update(WIN.blit(writing, (x-(writing.get_width()//2),y-(writing.get_height()//2))))
print(typing)
while True:
event = pygame.event.wait()
if event.type == pygame.QUIT:
run=False
pygame.quit()
break
if event.type == pygame.KEYDOWN:
break
我也试过在 if 语句行的末尾使用 pygame.display.update() 但这也失败了。
在某些系统上,如果您没有从系统中获取 pygame.event
,PyGame
将无法正常工作 - 系统可能会认为程序挂起,甚至可能会关闭它。
您可能需要在循环中使用 pygame.even.get()
(或类似函数)。
在文档pygame.event中你可以找到(但它隐藏在长描述中)
To prevent lost events, especially input events which signal a quit command, your program must handle events every frame (with pygame.event.get(), pygame.event.pump(), pygame.event.wait(), pygame.event.peek() or pygame.event.clear()) and process them.
Not handling events may cause your system to decide your program has locked up.
To keep pygame in sync with the system, you will need to call pygame.event.pump() internally process pygame event handlers to keep everything current.
当 运行 我正在将一些文本 blit'ing 到我的表面 (WIN) 并且我希望在游戏中显示它所以我调用 pygame.display.update 来更新显示,这非常有效很好,直到循环迭代了大约 75 次,此后显示停止更新。下面的代码
def dialogue(x,y,text):
global clock
global run
typing=True
tempstring=""
counter=0
switcher=0
for z in range(0,(len(text))):
clock.tick(15)
tempstring=text[0:z+1]
counter+=1
print(counter)
print("temp is "+tempstring)
writing=TITLE_FONT.render(tempstring, 1, (255,255,255),(0,0,0))
if x==-1 and y>-1:
pygame.display.update(WIN.blit(writing, (640-(writing.get_width()//2),y-(writing.get_height()//2))))
elif x>-1 and y==-1:
pygame.display.update(WIN.blit(writing, (x-(writing.get_width()//2),360-(writing.get_height()//2))))
elif x==-1 and y==-1:
pygame.display.update(WIN.blit(writing, (640-(writing.get_width()//2),360-(writing.get_height()//2))))
else:
pygame.display.update(WIN.blit(writing, (x-(writing.get_width()//2),y-(writing.get_height()//2))))
print(typing)
while True:
event = pygame.event.wait()
if event.type == pygame.QUIT:
run=False
pygame.quit()
break
if event.type == pygame.KEYDOWN:
break
我也试过在 if 语句行的末尾使用 pygame.display.update() 但这也失败了。
在某些系统上,如果您没有从系统中获取 pygame.event
,PyGame
将无法正常工作 - 系统可能会认为程序挂起,甚至可能会关闭它。
您可能需要在循环中使用 pygame.even.get()
(或类似函数)。
在文档pygame.event中你可以找到(但它隐藏在长描述中)
To prevent lost events, especially input events which signal a quit command, your program must handle events every frame (with pygame.event.get(), pygame.event.pump(), pygame.event.wait(), pygame.event.peek() or pygame.event.clear()) and process them.
Not handling events may cause your system to decide your program has locked up.
To keep pygame in sync with the system, you will need to call pygame.event.pump() internally process pygame event handlers to keep everything current.