是這樣的:
#upcount
import pygame, sys
from pygame.locals import *
pygame.init()
size = width, height = 200, 200
screen = pygame.display.set_mode(size)
font = pygame.font.SysFont('arial', 20)
increase_event = pygame.USEREVENT + 1
number_change_time = 1000 # 1 second
def main():
pygame.time.set_timer(increase_event, number_change_time)
global dodged
dodged = 0
while True:
event_loop()
update()
def event_loop():
global dodged
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
pygame.time.set_timer(increase_event, 0) # stop the timer on keypress
if event.type == increase_event:
dodged += 1
def update():
global dodged
screen.fill((0,0,0))
numstr = str(dodged)
mytext = font.render(numstr, True, (255,255,0))
mytext = mytext.convert_alpha()
screen.blit(mytext, (20, 30))
pygame.display.flip()
if __name__=="__main__":
main()
我沒有得到一個錯誤,但它像以前一樣的工作方式相同什麼NU我是否編輯改變它有多大?我試着改變number_change_time變量爲10,但它的工作原理是一樣的。 – 0swald
number_change_time以毫秒爲單位。你可能會混淆單位。 – ppperry