我对 Pygame 和 Python 很陌生,我刚刚编写了第一个代码,但不知何故我不断收到此错误:
TypeError: 'pygame.Surface' object is not callable
我不知道代码是否有问题,或者只是因为Pygame/Python安装不正确。
bif="bg.jpg"
mif="ball.png"
import pygame, sys
from pygame.locals import *
pygame.init()
screen=pygame.display.set_mode((640,360),0,32)
background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
screen.blit(background, (0,0))
x,y = pygame.mouse.get_pos()
x -= mouse_c.get_width()/2
y -= mouse_c.get_height()/2
screen.blit(mouse_c(x,y))
pygame.display.update()
运行此代码后,pygame 窗口崩溃。
你少了一个逗号:
screen.blit(mouse_c(x,y))
应该
screen.blit(mouse_c, (x,y))
# ^
在第一个版本中,mouse_c(x, y)
被解释为试图call mouse_c
(这是一个pygame.Surface
因此不可调用)带参数x
and y
,当它们实际上是单独的参数时(source
and dest
) to screen.blit.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)