如何制作透明的pygame.draw.circle [英] How to make transparent pygame.draw.circle
本文介绍了如何制作透明的pygame.draw.circle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使 pygame.draw.circle
透明(添加 alpha 级别),至于surface"set_alpha"?我找到了一个解决方案,只是将 pygame.draw.circle
的颜色更改为不那么亮
解决方案
你必须使用
导入pygamepygame.init()wndsize = (400, 400)窗口 = pygame.display.set_mode(wndsize)时钟 = pygame.time.Clock()运行 = 真运行时:时钟滴答(60)对于 pygame.event.get() 中的事件:如果 event.type == pygame.QUIT:运行 = 错误window.fill(0)pygame.draw.rect(窗口, (0, 0, 255), (0, 0, 200, 400))半径 = 100circle = pygame.Surface((radius*2, radius*2), pygame.SRCALPHA)pygame.draw.circle(circle, (255, 0, 0, 128), (radius, radius), radius)window.blit(circle, (100, 100))pygame.display.flip()
How to make pygame.draw.circle
transparent (add alpha level), as for "surface" "set_alpha"?
I found a solution only in changing the color of pygame.draw.circle
to less bright
解决方案
You've to use a pygame.Surface
. Create a Surface with a per pixel alpha image format. e.g:
radius = 100
circle = pygame.Surface((radius*2, radius*2), pygame.SRCALPHA)
And draw a transparent circle on it. The color of the circle has to have an alpha channel < 255 (e.g. 128):
pygame.draw.circle(circle, (255, 0, 0, 128), (radius, radius), radius)
blit()
the Surface to the window. e.g.:
window.blit(circle, (100, 100))
Example:
import pygame
pygame.init()
wndsize = (400, 400)
window = pygame.display.set_mode(wndsize)
clock = pygame.time.Clock()
run = True
while run:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
window.fill(0)
pygame.draw.rect(window, (0, 0, 255), (0, 0, 200, 400))
radius = 100
circle = pygame.Surface((radius*2, radius*2), pygame.SRCALPHA)
pygame.draw.circle(circle, (255, 0, 0, 128), (radius, radius), radius)
window.blit(circle, (100, 100))
pygame.display.flip()
这篇关于如何制作透明的pygame.draw.circle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文