簡體   English   中英

類型錯誤:__init__() 缺少 2 個必需的位置參數:子彈射擊系統的“x”和“y”

[英]TypeError: __init__() missing 2 required positional arguments: 'x' and 'y' for bullet shooting system

當我運行這段代碼時,它說我有一個錯誤:

TypeError: __init__() missing 2 required positional arguments: 'x' and 'y'

我打電話給班級並將他們添加到一個組中:

kunai = Kunai()
kunai_sprites = pg.sprite.Group() #puts all the kunai sprites into a group

這是課程:

#throwing projectile (kunai)
class Kunai(pg.sprite.Sprite): #creating the kunai class
    def __init__(self, x, y): #initialising the kunai
        pg.sprite.Sprite.__init__(self)
        self.image = pg.Surface((10,20))
        self.image.fill(RED)
        self.velocity = 35
        self.rect = self.image.get_rect()
        self.rect.bottom = y
        self.rect.centrex = x

#drawing a circle which will determine the throwing range of the kunai
    def update(self):
        self.rect.y = self.rect.y + self.velocity #the kunai moves at set speed
        if self.rect.bottom < 0: #if the sprite crosses 
            self.kill() #it removes the sprite

你需要做。

kunai = Kunai(x,y)

就像錯誤所說的那樣,您在初始化中缺少兩個參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM