Hey Guys Im writing a little Pong-Game in Pygame and wanted to use a glowing-effect on the Ball and the Bats. But Pygame dosen't support this effects and make solid block's out of it. Is there a way to handle that with lighting?
thanks in advance
Hey Guys Im writing a little Pong-Game in Pygame and wanted to use a glowing-effect on the Ball and the Bats. But Pygame dosen't support this effects and make solid block's out of it. Is there a way to handle that with lighting?
thanks in advance
Sadly, pygame itself does not offer any built-in lighting/glowing effects. However, I have discovered a nice effect, that with tweaking, might even pass as glowing. The idea is that you draw many concentric circles around your ball, each with a diminishing light value. This looks like it is casting a small sphere of light around it. Example:
>>> import pygame
>>> screen = pygame.display.set_mode((400, 300))
>>> pygame.display.set_caption("Glowy ball")
>>> screen.fill([0, 0, 0])
<rect(0, 0, 400, 300)>
>>> circs = [17, 17, 17, 17, 17, 16, 16, 16, 17, 17, 17, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 2, 1, 1, 1]
>>> for i in range(len(circs)):pygame.draw.circle(screen, [circs[i]*15]*3, (200, 150), i+1, 1)
The result:
As this is not proper lighting, it will get drawn on top of walls, or other objects. The simplest way to work around this is to draw the lighting separately, and first, so that everything else will be drawn on top of it. If you are looking for a slightly more professional quality, some ray tracing could go a long way.