微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python3,Pygame Sprite.Group更新方法参数不同

如何解决Python3,Pygame Sprite.Group更新方法参数不同

浏览Eric Matthes撰写的《 Python崩溃课程》一书,我在vscode实现中收到一条警告。警告显示为“ 参数与覆盖的'update'方法pylint(arguments-differ)) 不同”

我有一个从pygame模块的Sprite类继承的类。在该类中,我使用update方法。我用书中的内容仔细检查了我的实现。我看不到我做错了。阅读pygame文档上的更新方法update(),我得出的结论是该方法需要两个输入参数,但是我不给它们任何输入。因此,警告?从文档中:

* update() 在包含的Sprite上调用update方法 update(* args,* kwargs)->无 在组中的所有Sprite上调用update()方法。 Sprite基类具有一个update方法,该方法接受任意数量的参数,并且不执行任何操作。

我的问题是:我应该担心警告吗?我的意思是,0个参数符合任意数量的参数。参见下面的Bullet类:

"""Bullet module"""
import pygame
from pygame.sprite import Sprite

class Bullet(Sprite):
    """A class to manage bullets fired from the ship"""

    def __init__(self,ai_settings,screen,ship):
        """Create bullet object at the ship's current position"""
        super().__init__()
        self.screen = screen

        # Create a bullet rect at (0,0) and then set correct position
        self.rect = pygame.Rect(0,ai_settings.bullet_width,ai_settings.bullet_height)
        self.rect.centerx = ship.rect.centerx   # Align bullet with ship x position
        self.rect.top = ship.rect.top           # Align bullet with ship nose

        # Store the bullet's position as a decimal value
        self.y = float(self.rect.y)

        self.color = ai_settings.bullet_color
        self.speed_factor = ai_settings.bullet_speed_factor

    def update(self):
        """Move bullet on top of screen"""
        # Update the decimal position of the bullet.
        self.y -= self.speed_factor
        # Update the rect position.
        self.rect.y = self.y

    def draw_bullet(self):
        """Draw the bullet on screen"""
        pygame.draw.rect(self.screen,self.color,self.rect)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。