[英]TypeError: 'pygame.Surface' object is not callable and pygame window crashes
我对 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)
被解释为尝试使用参数x
和y
调用mouse_c
(这是一个pygame.Surface
,因此不可调用),而实际上它们是单独的参数( source
和dest
)screen.blit
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.