2017-07-30 8 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を使用していなかったので、エラーメッセージが表示されず、コードが正常に動作していると見なされました。 –

関連する問題