繁体   English   中英

使用pygame制作角色类,不断出错:TypeError:__init __()缺少1个必需的位置参数:'self'

[英]Using pygame and making class for a character, keep getting error: TypeError: __init__() missing 1 required positional argument: 'self'

使用此代码:

import pygame

class Creature(pygame.sprite.Sprite):
    pygame.sprite.Sprite.__init__()

class Human(Creature):

    def __init__(self):
        super.__init__()

        self.image = pygame.image.load('resources/images/Protag.png')

        pygame.draw(self.image)

        self.rect = self.image.get_rect()

    def moveRight(self, pixels):
        self.rect.x += pixels

    def moveLeft(self, pixels):
        self.rect.x -= pixels

我一直在标题中得到错误。 我在网上遵循了教程,但仍然遇到此错误。 有什么想法吗?

在您的Human类中,在__init__函数中将其更改为this(对于Python 2):

super(Human, self).__init__()

如果您使用的是Python 3,则:

super()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM