2

I want to make a partially transparent circle as an area of effect indicator, but I haven't found any way to do this in pygame.

I tried passing in an rgba 4-tuple as an argument (as suggested by this post), but it didn't change the transparency at all. On top of that, according to this other post, the method shouldn't work at all, since draw doesn't accept alpha values. That's conflicting information.

pygame.draw.circle(screen, (255, 0, 0, 100), (x, y), r)

I've also tried creating a new surface, drawing the circle onto that surface, and then blitting the new surface onto my game screen (as suggested by this post). It gives me a semi-transparent circle as requested, but since surfaces in pygame are rectangular, it also gives me a gray rectangle around the circle, which I don't want.

s = pygame.Surface((1000, 1000))
s.set_alpha(100)
pygame.draw.circle(s, (255, 0, 0), (x, y), r)
screen.blit(s, (0, 0))

Is there any way to make this circle semi-transparent without adding any other visible effects to my screen?

1 Answers1

2

Here's a runnable version of the answer to the last question you linked to titled How to draw a semi-transparent circle in Pygame?. It seems to do what you want, as far as I can tell.

import pygame

width, height = 640, 480

pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((width,height))
surface = pygame.display.set_mode((width,height), pygame.SRCALPHA)

while True:
    msElapsed = clock.tick(100)
    screen.fill((255,255,255))
    pygame.draw.circle(surface,(30,224,33,100),(250,100),10)
    screen.blit(surface, (0,0))
    pygame.display.update()

    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            exit()
martineau
  • 119,623
  • 25
  • 170
  • 301