【问题标题】:Pygame: Set alpha level for shapesPygame:为形状设置 alpha 级别
【发布时间】:2013-11-14 01:53:34
【问题描述】:

我将如何设置 pygame 形状的 alpha 值:pygame.draw.circle()

我尝试使用 RGBA 值,但无济于事。这是绘制代码:

pygame.draw.circle(screen, ((0,255,0,alpha)), (px,py), 15)

pxpy 是玩家(圆圈)的位置。 alpha 只是我认为是 alpha 值的占位符。

有人有什么想法吗?

【问题讨论】:

    标签: python pygame draw


    【解决方案1】:

    draw.circle() 不使用alpha,因此您必须使用Surface()(获取位图)并将alphacolorkey 添加到Surface()

    import pygame
    
    pygame.init()
    
    screen = pygame.display.set_mode((800, 600), 0, 32)
    
    surface1 = pygame.Surface((100,100))
    surface1.set_colorkey((0,0,0))
    surface1.set_alpha(128)
    pygame.draw.circle(surface1, (0,255,0), (50,50), 50)
    
    surface2 = pygame.Surface((100,100))
    surface2.set_colorkey((0,0,0))
    surface2.set_alpha(128)
    pygame.draw.circle(surface2, (255,0,0), (50,50), 50)
    
    screen.blit(surface1, (100,100))
    screen.blit(surface2, (120,120))
    
    pygame.display.update()
    
    RUNNING = True
    
    while RUNNING:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                RUNNING = False
    
    pygame.quit()
    

    【讨论】:

      【解决方案2】:

      pygame.draw.circle

      好像 circle() 函数不支持 alpha。如果你想通过pygame绘制半透明的圆形,你可以加载一个包含alpha(即PNG)的图像作为表面,然后设置alpha值。

      【讨论】:

      • 这就是我最终做的!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-19
      • 1970-01-01
      • 1970-01-01
      • 2012-11-08
      相关资源
      最近更新 更多