Avoid surface.copy for the cases where we blow away the contents
authorNeil <neil@dip.sun.ac.za>
Wed, 7 Sep 2016 14:29:55 +0000 (16:29 +0200)
committerNeil <neil@dip.sun.ac.za>
Wed, 7 Sep 2016 14:29:55 +0000 (16:29 +0200)
tabakrolletjie/lights.py

index 2c691fefa9b508b53a07872eadff5702fff1e8f9..e47fa149fe311793a8452107fec1ed40964c7cdc 100644 (file)
@@ -5,6 +5,7 @@ import pymunk
 import pymunk.pygame_util
 import pygame.display
 import pygame.draw
+import pygame.locals as pgl
 
 from .constants import (
     SCREEN_SIZE, LIGHT_CATEGORY, FITTINGS_CATEGORY)
@@ -173,7 +174,7 @@ class BaseLight(object):
         if not self.on:
             return
 
-        raypoly_mask = surface.copy()
+        raypoly_mask = pygame.surface.Surface(surface.get_size(), pgl.SWSURFACE)
         white, black = (255, 255, 255, 255), (0, 0, 0, 0)
         raypoly_mask.fill(black)
         for shape in self.body.shapes:
@@ -185,7 +186,7 @@ class BaseLight(object):
             pygame.draw.polygon(raypoly_mask, white, pygame_poly, 0)
             pygame.draw.aalines(raypoly_mask, white, True, pygame_poly, 1)
 
-        limits_mask = surface.copy()
+        limits_mask = pygame.surface.Surface(surface.get_size(), pgl.SWSURFACE)
         limits_mask.fill(black)
         centre = pymunk.pygame_util.to_pygame(self.position, surface)
         max_radius = self.radius_limits[1] or 50.0
@@ -204,12 +205,11 @@ class BaseLight(object):
         pygame.draw.arc(
             limits_mask, white, box3, start_angle, end_angle, int(width))
 
-        import pygame.locals as pgl
         raypoly_mask.blit(limits_mask, (0, 0), None, pgl.BLEND_RGBA_MIN)
         raypoly_mask.set_colorkey(black)
 
         light_colour = self.COLOURS[self.colour]
-        overlay = surface.copy()
+        overlay = pygame.surface.Surface(surface.get_size(), pgl.SWSURFACE)
         overlay.fill(light_colour)
         raypoly_mask.blit(overlay, (0, 0), None, pgl.BLEND_RGBA_MULT)