【发布时间】:2019-10-15 00:18:49
【问题描述】:
我的游戏中有一些精灵需要特定部分才能改变颜色。
我的过程我试图让一个纯白色的精灵图像在不需要颜色的任何地方都是透明的。我在上面画了一个彩色方块,然后在主精灵的顶部,但是主精灵然后到处改变颜色,但同时尊重主精灵的透明度。最让我困惑的部分是,当我将蒙版的彩色图像放在主屏幕上时,它看起来确实正确。
# Load main sprite and mask sprite
self.image = pygame.image.load("Enemy.png").convert_alpha()
self.mask = pygame.image.load("EnemyMask.png").convert_alpha()
# Create coloured image the size of the entire sprite
self.coloured_image = pygame.Surface([self.width, self.height])
self.coloured_image.fill(self.colour)
# Mask off the coloured image with the transparency of the masked image, this part works
self.masked = self.mask.copy()
self.masked.blit(self.coloured_image, (0, 0), None, pygame.BLEND_RGBA_MULT)
# Put the masked image on top of the main sprite
self.image.blit(self.masked, (0, 0), None, pygame.BLEND_MULT)
蒙版颜色Masked Colour
最终失败的 Sprite Failed Sprite
无法发布图片,没有足够的声誉
我没有错误,但只有盾牌的白色部分应该是绿色的
【问题讨论】:
-
我看不到您的图片,它们需要 Google 帐户。 (除了第一张图片。)
-
我刚刚更改了一些内容,想看看第二张图片现在是否适合您。
self.colour没有 alpha,但也只有纯色
标签: python pygame sprite pygame-surface