How can I draw a rectangle that has a color with an alpha? I have:
windowSurface = pygame.display.set_mode((1000, 750), pygame.DOUBLEBUF)
pygame.draw.rect(windowSurface, pygame.Color(255, 255, 255, 128), pygame.Rect(0, 0, 1000, 750))
But I want the white rectangle to be 50% transparent, but the alpha value doesn't appear to be working.
You can add a fourth value to your color tuple to represent Alpha:
pygame.draw
functions will not draw with alpha. The documentation says:What you can do is create a second surface and then blit it to the screen. Blitting will do alpha blending and color keys. Also, you can specify alpha at the surface level (faster and less memory) or at the pixel level (slower but more precise). You can do either:
or,
Keep in mind in the first case, that anything else you draw to
s
will get blitted with the alpha value you specify. So if you're using this to draw overlay controls for example, you might be better off using the second alternative.Also, consider using pygame.HWSURFACE to create the surface hardware-accelerated.
Check the Surface docs at the pygame site, especially the intro.
the most i can do to help you is to show you how to draw a rectangle that is not filled in. the line for the rectangle is:
the "1" means that it is not filled in