0
所以我想創建一個計時器,當遊戲運行時,遊戲運行的秒數將顯示在我的pygame窗口中。但由於某種原因,它似乎並不奏效。我不太確定這個問題到底是什麼。 35-44(Pygame).blit將不會顯示雖然功能
行是定時器功能是... 71 行是時間預計將顯示...
import pygame
pygame.init()
pygame.font.init()
FPS = 60
fpsClock = pygame.time.Clock()
time = 10
WHITE = (255,255,255)
dimension = [936, 520]
SCREEN = pygame.display.set_mode(dimension)
font = pygame.font.Font("8-BIT WONDER.TTF",16)
gameEnd= False
#Images
blacksmith = pygame.image.load("blacksmith.png")
blacksmith = pygame.transform.scale(blacksmith,(144,144))
background = pygame.image.load("background_img.png")
#Positions
blacksmith_position = [400,275]
anvil_position = [0,0]
song = pygame.mixer.music.load("Pixelland.mp3")
pygame.mixer.music.play(0, 0.0)
#Time
get_time = True
#Clock
while get_time == True:
time = pygame.time.get_ticks()/1000
pygame.time.delay(1000)
display_time = font.render(time, True, WHITE)
#Game Loop
while not gameEnd:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameEnd = True
#Player Controls
keys = pygame.key.get_pressed()
if keys[pygame.K_F11]:
pygame.display.toggle_fullscreen()
if keys[pygame.K_LEFT]:
blacksmith_position[0] = max(95, blacksmith_position[0] - 12)
if keys[pygame.K_RIGHT]:
blacksmith_position[0] = min(685, blacksmith_position[0] + 12)
SCREEN.blit(background, (0, 0))
SCREEN.blit(blacksmith,(blacksmith_position))
SCREEN.blit(display_time, (70,10))
pygame.display.update()
fpsClock.tick(FPS)
pygame.quit()
quit()
執行'而GET_TIME ==真:'這一切停止。你可以只有一個所有時間運行的while循環(無盡的) – furas