gpt4 book ai didi

python - 如何制作透明的pygame.draw.circle

转载 作者:行者123 更新时间:2023-12-02 04:49:14 26 4
gpt4 key购买 nike

如何制作pygame.draw.circle透明(添加 alpha 级别),至于“表面”“set_alpha”?我找到了只能改变 pygame.draw.circle 颜色的解决方案调至较暗

最佳答案

您必须使用pygame.Surface 。创建具有每像素 alpha 图像格式的 Surface。例如:

radius = 100
circle = pygame.Surface((radius*2, radius*2), pygame.SRCALPHA)

并在其上画一个透明的圆圈。圆圈颜色的 Alpha channel 必须 < 255(例如 128):

pygame.draw.circle(circle, (255, 0, 0, 128), (radius, radius), radius)

blit() Surface 到窗口。例如:

window.blit(circle, (100, 100))

示例:

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()

关于python - 如何制作透明的pygame.draw.circle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59293057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com