簡體   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