且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将图像的背景颜色与 Pygame 的背景颜色匹配?

更新时间:2021-11-30 18:06:16

如果图像具有透明背景,请尝试在 game_Character.py 中执行以下操作:

if the image has a transparent background try doing the following in game_Character.py:

# Load image and get rect
    self.image = pygame.image.load("Images/supermen.bmp").convert_alpha()
    self.rect = self.image.get_rect()
    self.screen_rect = screen.get_rect()

如果它有白色背景,你可能想像这样设置颜色键:

If it has a white background you probably want to set the colorkey like so:

    # Load image and get rect
        self.image = pygame.image.load("Images/supermen.bmp").convert()
        self.image.set_colorkey((255, 255, 255))
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()