Pygame窗口没有显示任何东西
问题描述:
嗨我对Pygame很新,我想让窗口显示一个紫色的屏幕,在左上方有一个FPS计数器;然而,它总是显示一个没有任何内容的黑屏。当我运行我的代码时,它根本不显示任何错误。Pygame窗口没有显示任何东西
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的很抱歉,如果这是一个明显的错误
答
有多种语法错误。如果你看不到错误信息,请安装一个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():
如果你是初学者,你应该从运行示例开始,然后调整它们以理解它是如何工作的。不要尝试写甚至没有测试的几十行...
+0
非常感谢!我没有为这个IDE使用IDE,这就是为什么我看不到错误信息并假定代码工作正常。 –
你的代码甚至没有运行,它的错误充满。 – Johannes