I am creating a 2D dungeon crawler using Pygame, and I want to use the main character as a light source (so you can only see a small amount of the dungeon around you). I have created an alpha mask, but no matter how big I make my alpha mask, it isn't making any difference to the size of the light source and it's too small. Is there a better way to do this in PyGame, or am I overlooking something?
Here is my test code:
import pygame
pygame.init()
screen = pygame.display.set_mode((819, 614))
background = pygame.image.load('Test.png')
light = pygame.image.load('Light_Source.png')
overlay_colour = [73, 92, 115]
while True:
for e in pygame.event.get():
if e.type == pygame.QUIT:
break
else:
screen.blit(background, (0, 0))
overlay = pygame.surface.Surface((819, 614))
overlay.fill(overlay_colour)
overlay.blit(light, (300, 250))
screen.blit(overlay, (0, 0), special_flags=pygame.BLEND_RGBA_SUB)
pygame.display.flip()
continue
break
Here is my test screen (Test.png):
Here is what my alpha mask currently looks like:
And here is my alpha mask (Light_Source.png):
As you can see, it's pretty lame. But increasing the dimensions of my Light_Source.png file has no effect, and neither does expanding the alpha gradient to fill more of the image. I cannot figure out why this won't work. Am I filling the overlay with the wrong colour? Can anyone see a problem? Or have a better way of doing this please?