我正在使用 pygame 中的自定义 gui 组件,并且在制作滑块组件时,我为滑块提供了一个Draw(parentSurface)
函数,该函数将滑块绘制到其存储位置的父表面上。
现在这可行,但滑块存储两个图像:
- 一个幻灯片图像,它是由瓦片动态制成的,以匹配滑块的给定长度,以给定长度的宽度和 3 像素的高度进行测量;和
- “选择”图像,它只是一个小的 8x12 指示器,用于显示滑块的位置。
问题是当我Draw(parentSurface)
这样做时:
def Draw(self, parsurf):
'''draw the element on parsurf at the given location'''
w1 = self.slider_img.get_width()
h1 = self.slider_img.get_height()
w2 = self.select_img.get_width()
h2 = self.select_img.get_height()
self.image = pygame.Surface((w1, h2 + h1))
self.image = ColorMod.Transparency(self.image, 0)
self.image.blit(self.slider_img, (0, self.image.get_height()-h1))
x = self.value / self.conversionratio
self.image.blit(self.select_img, (x- w2/2, 0))
if self.debug_on:
print "attempting to blit to the given surface"
parsurf.blit(self.image, self.loc)
但是,它在self.image
. 我希望它是半透明的,这样背景就可以通过self.image
. 我应该放弃拥有并将and直接self.image
绘制到父表面吗?self.slider_img
self.select_img