我正在尝试制作一个游戏pygame库。但是有一个错误。 我看了一些论坛,但我无能为力。 如果可以帮助我,我很高兴。
File C:/Users/User/PycharmProjects/zaxd/main.py", line 34, in <module>
screen.blit(playerImg(playerX, playerY))
TypeError: pygame.Surface object is not callable
''' 导入pygame
# Initialize library
pygame.init()
# Variables
running = True
pd = pygame.display
pi = pygame.image
# Create Screen
screen = pygame.display.set_mode((800, 600))
# Caption and Icon
pd.set_caption("Space Invaders")
icon = pi.load('ufo.png')
pd.set_icon(icon)
# Player
playerImg = pi.load('plane.png')
playerX = 370
playerY = 480
def player():
screen.blit(playerImg(playerX, playerY))
# Game Loop
while running:
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event == pygame.QUIT:
running = False
# Change BG Color (Black)
player()
pd.update()
'''
答案 0 :(得分:2)
您错过了playerImg和(x,y)坐标之间的逗号
screen.blit(playerImg,(playerX, playerY))