如何在精灵上绘制精灵,以便在 pygame 中都能看到它们

问题描述

我有两个精灵,其中一个是坦克精灵,另一个是保护精灵。我想在坦克精灵上绘制保护精灵。精灵图片如下:

enter image description here

enter image description here

当我在坦克精灵上绘制保护精灵时,结果如下:

enter image description here

保护精灵的中心是空的(根据photoshop,我检查了多次)。我将以下代码用于保护精灵

self.image = pygame.transform.scale(
        pygame.image.load(os.path.join(imgFolderExp,"Powerups","protection-3.png")).convert(),(40,48))
self.image.set_colorkey((0,0))

我应该怎么做才能只画保护精灵的线条,以便在组合画的中间看到坦克?

解决方法

PNGs 具有每像素 alpha。没有必要设置颜色键。只需blit 坦克上的保护器。 convert() 将像素格式更改为没有每像素 alpha 的格式并删除透明度信息。改用 convert_alpha()

filepath = os.path.join(imgFolderExp,"Powerups","protection-3.png") 

protector_surf = pygame.image.load(filepath).convert_alpha()

self.image = pygame.transform.scale(protector_surf,(40,48))