我是使用python 3.7的初学者,只是不能确定正确地编辑pygame的时间。如果游戏得分> 100,我想显示一些文本,并且我知道我不能在“文本”上使用“打印”,因为它显示在程序栏上,而不是程序本身(就像我想看到)
我已经尝试定义时间(分数,文字): 并只放def time():
赞:
import sys
import pygame
import time
def time():
time.sleep(5)
if score > 100:
text = "X"
label = myFont.render(text, 1, WHITE)
screen.blit(label, (WIDTH-100, HEIGHT-50))
并且:
import sys
import pygame
import time
def time(score, text):
time.sleep(5)
if score > 100:
text = "X"
label = myFont.render(text, 1, WHITE)
screen.blit(label, (WIDTH-100, HEIGHT-50))
答案 0 :(得分:0)
if语句的缩进是错误的。您需要将其设置为与time.sleep(5)
相同的级别,请尝试以下操作:
def time(score, text):
time.sleep(5)
if score > 100:
text = "X"
label = myFont.render(text, 1, WHITE)
screen.blit(label, (WIDTH-100, HEIGHT-50))