我正在玩pygame游戏,在制作这个游戏时我在屏幕上使用了大量文字。但是当我在我的代码中达到这一点时,首先写入的文本不会闪烁,但第二个文件会闪烁,我想改变它。另外,当我拿着一把钥匙的时候,我只是想要一次又一次地写这封信时,这封信会被反复写入。代码:
def game_loop():
while True:
clock = pygame.time.Clock()
def enter_name():
global kiriko
global pressed_key
global ikey
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1 :
pressed_key = '1'
if event.key == pygame.K_2 :
pressed_key = '2'
if event.key == pygame.K_3 :
pressed_key = '3'
if event.key == pygame.K_4 :
pressed_key = '4'
if event.key == pygame.K_5 :
pressed_key = '5'
if event.key == pygame.K_6 :
pressed_key = '6'
if event.key == pygame.K_7 :
pressed_key = '7'
if event.key == pygame.K_8 :
pressed_key = '8'
if event.key == pygame.K_9 :
pressed_key = '9'
if event.key == pygame.K_0 :
pressed_key = '0'
if event.key == pygame.K_q :
pressed_key = 'q'
if event.key == pygame.K_w :
pressed_key = 'w'
#same thing but for every letter in the alphabet...
if event.key == pygame.K_PLUS :
pressed_key = '+'
if event.key == pygame.K_BACKSPACE :
kiriko = kiriko[:-1]
if event.type == pygame.KEYUP:
pressed_key = ''
try:
message_small(kiriko, display_width / 2, display_height / 1.3)
message_display("Enter your name")
pygame.display.update()
window.fill(white)
enter_name()
kiriko += pressed_key
message_small(kiriko, display_width / 2, display_height / 1.3)
message_display("Enter your name")
pygame.display.update()
clock.tick(120)
except:
message_small(kiriko, display_width / 2, display_height / 1.3)
message_display("Enter your name")
pygame.display.update()
window.fill(white)
enter_name()
message_display("Enter your name")
pygame.display.update()
clock.tick(120)
编辑:现在唯一的问题是闪烁文本,因为我得到了
的解决方案答案 0 :(得分:0)
我相信你的文字闪烁的原因是因为你在很多地方打电话pygame.display.update()
。只需在代码结束时拨打pygame.display.update()
。
〜Mr.Python