2017-07-30 224 views
-1

嗨我對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的很抱歉,如果這是一個明顯的錯誤

+0

你的代碼甚至沒有運行,它的錯誤充滿。 – Johannes

回答

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():

如果你是初學者,你應該從運行示例開始,然後調整它們以理解它是如何工作的。不要嘗試寫甚至沒有測試的幾十行...

+0

非常感謝!我沒有爲這個IDE使用IDE,這就是爲什麼我看不到錯誤信息並假定代碼工作正常。 –