2017-10-21 52 views
0

當我有下面的代碼有問題:錯誤編碼pygame的RPG


import pygame, sys, time 
 
from scripts.UltraColor import * 
 

 
pygame.init() 
 

 
cSec = 0 
 
cFrame = 0 
 
FPS = 0 
 

 
fps_font = pygame.font.Font("C:\\Windows\\Fonts\\Verdana.ttf", 20) 
 

 

 
def show_fps(): 
 
    fps_overlay = fps_font.render(str(FPS), True, color.Goldenrod) 
 
    window.blit(fps_overlay, (0, 0)) 
 

 

 
def create_window(): 
 
    global window, window_height, window_width, window_title 
 
    window_width, window_height = 1280, 720 
 
    window_title = "The Adventure of Nate" 
 
    pygame.display.set_caption(window_title) 
 
    window = pygame.display.set_mode((window_width, window_height, pygame.HWSURFACE | pygame.DOUBLEBUF)) 
 

 

 
def count_fps(): 
 
    global cSec, cFrame, FPS 
 

 
    if cSec == time.strftime("%S"): 
 
     cFrame += 1 
 

 
    else: 
 
     FPS = cFrame 
 
     cFrame = 0 
 
     cSec = time.strftime("%S") 
 

 

 
create_window() 
 

 
isrunning = True 
 

 
while isrunning == True: 
 
    for event in pygame.event.get(): 
 
     if event.type == pygame.QUIT: 
 
      isrunning = False 
 

 
    # LOGIC 
 

 
    count_fps() 
 

 
    # Rendering Graphics 
 

 
    window.fill(color.Black) 
 

 
    show_fps() 
 

 
    pygame.display.update() 
 

 
pygame.quit() 
 
sys.exit()


此代碼返回以下錯誤:

C: \ Python3.6 \ python.exe「C:/ Users/home/PycharmProjects/Basic RPG/Base Game.py」 Traceback(最近一次調用最後一次): 文件「C:/ Users/home/PycharmProjects/C:\ Program Files \ C:/ Users/home/PycharmProjects/Basic RPG/Base Game.py」,line 38,in create_window基本RPG /基地Game.py」 23行,在create_window 窗口= pygame.display.set_mode((window_width,window_height,pygame.HWSURFACE | pygame.DOUBLEBUF)) 類型錯誤:參數1必須是長度爲2的序列,沒有3

進程退出代碼爲1


如果有人知道如何解決這一代碼完成,可以請你回覆。

回答

0

正如你可以在the documentation,set_mode函數中看到一個元組(width, height)和其他參數。你正在傳遞一個元組。正確的代碼應該如下所示(注意括號):

window = pygame.display.set_mode((window_width, window_height), pygame.HWSURFACE | pygame.DOUBLEBUF) 
+0

非常感謝!在編碼方面,我是一個小菜鳥,所以我可以看到我是否會錯過這樣的事情。 –