Skip to content Skip to sidebar Skip to footer

How To Make A Circle Semi-transparent In Pygame?

I'm somewhat new to pygame and trying to figure out how to make a circle semi-transparent. The trick however is that the background for the circle also has to be transparent. Here

Solution 1:

A couple things. First, your surface definition should crash, as it missing a parenthesis. It should be:

surface = pygame.Surface((size, size), pygame.SRCALPHA, 32)

I assume that somewhere later in your code, you have something to the effect of:

mainWindow.blit(surface, (x, y))
pygame.display.update() #or flip

Here is your real problem:

>>>import pygame>>>print pygame.Color("black")
(0, 0, 0, 255)

Notice that 255 at the end. That means that pygame.Color("black") returns a fully opaque color. Whereas (0, 0, 0, 0) would be fully transparent. If you want to set the transparency, define the color directly. That would make your draw function look like:

pygame.draw.circle(
    surface, 
    (0, 0, 0, transparency), 
    (int(size/2), int(size/2)),
    int(size/2), 2)

Post a Comment for "How To Make A Circle Semi-transparent In Pygame?"