首页 > 解决方案 > 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()
    '''

标签: pythonpygame

解决方案


您在 playerImg 和 (x,y) 坐标之间缺少逗号

screen.blit(playerImg,(playerX, playerY))

推荐阅读