[英]TypeError: argument 1 must be pygame.Surface, not type
I'm making a submarine game in python, but when I try to run it, the interpreter gives me very strange error: "TypeError: argument 1 must be pygame.Surface, not type."我正在用 python 制作潜艇游戏,但是当我尝试运行它时,解释器给了我一个非常奇怪的错误:“TypeError:参数 1 必须是 pygame.Surface,而不是类型。” I tried to search the web for my answer, but it seems like this isn't very usual error.
我试图在网上搜索我的答案,但这似乎不是很常见的错误。 I also tried to find error by myself, but everything seemed fine to me.
我也试图自己找出错误,但对我来说一切都很好。 Here 's part of the code that I think error is in:
这是我认为错误所在的代码的一部分:
mina = pygame.image.load('mina.png')
class mina():
def __init__(self, x , y):
self.x = x
self.y = y
self.eksplozija = False
def naris(self):
screen.blit(mina, (self.x, self.y))
igralec = podmornica(150, 300, 10)
eksploziv = mina(700, 350)
metki = []
clock = pygame.time.Clock()
def grafika():
clock.tick(60)
screen.blit(ozadje, (0,0))
igralec.naris()
#line, that doesn't work:
eksploziv.naris()
for metek in metki:
metek.naris(screen)
pygame.display.flip()
The variable mina
and the class mina
have the same name.变量
mina
和类mina
具有相同的名称。 The class mina
shadows the variable mina
. mina
类mina
了变量mina
。 You need to rename one or the other.您需要重命名其中一个。 I recommend to rename the calss
mina
to Mina
, since Python classes use the CapWords convention ( PEP 8 -- Style Guide for Python Code ):我建议将 calss
mina
重命名为Mina
,因为 Python 类使用 CapWords 约定( PEP 8 -- Python 代码风格指南):
class mina():
class Mina():
eksploziv = mina(700, 350)
eksploziv = Mina(700, 350)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.