' pygame.Surface' object不可调用错误

时间:2018-02-19 07:57:04

标签: python pygame

我一直收到一条跟踪错误,上面写着“pygame.Surface”#39;对象不可调用。

这是我正在制作的剧本(它主要由Meloonatic Melons制作,但我是初学者试图学习的)

import pygame, sys, time
from Scripts.Textures import *

pygame.init()

cSec = 0
cFrame = 0
FPS = 0

tile_size = 32

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

sky = pygame.image.load("Graphics\\Sky.png")
Sky = pygame.Surface(sky.get_size(), pygame.HWSURFACE)
Sky.blit(sky, (0, 0))
del sky

def showFPS():
    fps_overlay = FPS_font.render(str(FPS), True, (104, 98, 7))
    window.blit(fps_overlay, (0, 0))


def createWindow():
    global window, window_width, window_height, window_title
    window_width, window_height = 800, 600
    window_title = "Mystic RPG"
    pygame.display.set_caption(window_title)
    window = pygame.display.set_mode((window_width, window_height), pygame.HWSURFACE|pygame.DOUBLEBUF)

def countFPS():
    global cSec, cFrame, FPS

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

createWindow()

isRunning = True

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

    countFPS()

    window.blit(Sky (0, 0))

    for x in range(0, 640, tile_size):
        for y in range(0, 480, tile_size):
            window.blit(Tiles.Grass, (x,y))

    showFPS()

    pygame.display.update()

pygame.quit()
sys.exit()

错误说

 Traceback (most recent call last):
  File "C:/Users/Zane/Desktop/Python RPG/Mystic RPG.py", line 52, in <module>
    window.blit(Sky (0, 0))
TypeError: 'pygame.Surface' object is not callable

我正在使用Python 3.6.4

任何人都知道出了什么问题以及如何解决它。

1 个答案:

答案 0 :(得分:2)

我不熟悉这个,但是在showFPS()函数中,你写了这个:

Window.blit(fps_overlay, (0, 0))

错误行第52行,你写下这个:

window.blit(Sky (0, 0))

我相信参数之间需要逗号。