我正在pygame中自定义gui组件上工作,在制作滑块组件时,我为滑块提供了一个Draw(parentSurface)
功能,可以将滑块绘制到其存储位置的父曲面上。
现在可以使用,但是滑块存储两个图像:
问题是当我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
。我是否应该放弃并直接将self.image
和绘制到父曲面上?self.slider_img
self.select_img
您还必须通过调用使图像透明化。self.image.set_alpha((0,0,0))
此外,self.image = pyame.Surface
您还需要将其更改为self.image = pygame.Surface((width, height), pygame.SRCALPHA)
我也建议您删除self.image = ColorMod.Transparency...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句