嗨,我是Pygame的新手,我想在左上方显示一个带有FPS计数器的紫色屏幕的窗口;然而,它不断显示黑屏,其中没有任何内容。当我运行我的代码时,它根本不显示任何错误。
import pygame
import time
from scripts.UltraColor import*
pygame.init()
currentSec = 0
currentFrame = 0
FramePerSec = 0
fps_font = pygame.font.Font("C:\\Windows\\Fonts\\Verdana.ttf", 20)
def count_FramePerSecond():
global currentSec, currentFrame, FramePerSec
# during the current second, this will record how many frames there are
if currentSec = time.strf("%S"):
currentFrame += 1
else:
FramePerSec = currentFrame
#records the frame that were added during the second
currentFrame = 0
#resets the counter back to zero so it can record during the next second
currentSec = time.strf("%S"):
#sets the current second variable to the current second
def show_FramesPerSecond():
fps_overlay = fps_font.render(str(FramesPerSecond), True, Color.Goldenrod)
window.blit(fps_overlay, (0,0))
def create_window():
global window, window_title window_height, window_width,
window_title = "Crappy RPG Game"
window_height = 700
window_width = 900
pygame.display.set_caption(window_title)
window = pygame.display.set_mode((window_height, window_width), pygame.HWSURFACE|pygame.DOUBLEBUF)
create_window():
is_gameRunning = True
while is_gameRunning:
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_gameRunning = False
#Logic
count_FramePerSecond()
#Render Graphics:
window.fill(255,0,255)
show_FramesPerSecond()
pygame.display.update()
pygame.quit()
quit()
我再次对堆栈溢出和pygame都很新,很抱歉,如果这是一个明显的错误
答案 0 :(得分:1)
有多种语法错误。如果您看不到错误消息,请安装一个可以显示给您的IDE(我不熟悉Windows抱歉)。
if currentSec = time.strf("%S"):
应该是:
if currentSec == time.strf("%S"):
此外:
currentSec = time.strf("%S"):
=>
currentSec = time.strf("%S")
此处global window, window_title window_height, window_width,
和:
中的逗号中缺少逗号:create_window():
如果您是初学者,则应首先运行示例,然后对其进行调整以了解其工作原理。如果没有测试就不要尝试写几十行......