python - Pygame 'pygame.Surface' 对象不可调用
问题描述
我正在尝试制作一个游戏 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()
'''
解决方案
您在 playerImg 和 (x,y) 坐标之间缺少逗号
screen.blit(playerImg,(playerX, playerY))
推荐阅读
- compiler-construction - 如何找到yacc规则的字符串?
- python - Python - 如果条件为 FALSE,则移至下一个列表元素
- python-3.x - 从整数列表中找到偶数的和
- javascript - 无法使用 jQuery 编辑、更新和取消表格单元格文本
- vagrant - 具有多集群的 Vagrantfile 设置
- python - 如何使用 python 将 LineString 中的多个点从 JSON 添加到 GeoJSON?
- embedded - 使用定时器 A0 以 1 kHz 的频率和 0.25 和 0.75 的占空比使连接到引脚 1.0 和 4.7 的板载 LED 闪烁
- python - 使用 Python 从 Azure 表存储中的表中获取最旧的 n 行
- excel - 意外的日期结果 - Excel VBA - 日月年混淆
- ssl - SEC_ERROR_REVOKED_CERTIFICATE 错误仅在 PC Firefox 上