Changeset 353:b67ea65dae2b for nagslang


Ignore:
Timestamp:
Sep 6, 2013, 2:34:43 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Faster tiled renderer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/render.py

    r349 r353  
    198198        self.outline = outline
    199199        self._tiled = None
     200        self._offset = None
    200201
    201202    def _make_surface(self, surface):
    202203        if not self._tiled:
    203204            size = surface.get_size()
    204             self._tiled = tile_surface(size, self._tile_image)
    205205            mask = pygame.surface.Surface(size, pgl.SRCALPHA)
    206206            mask.fill(pygame.color.Color(0, 0, 0, 0))
    207207            pointlist = [pymunk.pygame_util.to_pygame(p, surface)
    208208                         for p in self.outline]
    209             pygame.draw.polygon(mask, pygame.color.THECOLORS['white'],
    210                                 pointlist, 0)
    211             self._tiled.blit(mask, (0, 0), special_flags=pgl.BLEND_RGBA_MULT)
    212         return self._tiled
    213 
    214     def render(self, surface):
    215         tiled = self._make_surface(surface)
    216         surface.blit(tiled, (0, 0))
     209            rect = pygame.draw.polygon(mask, pygame.color.THECOLORS['white'],
     210                                       pointlist, 0)
     211            self._offset = (rect.x, rect.y)
     212            self._tiled = tile_surface((rect.w, rect.h), self._tile_image)
     213            self._tiled.blit(mask, (0, 0), rect,
     214                             special_flags=pgl.BLEND_RGBA_MULT)
     215
     216    def render(self, surface):
     217        self._make_surface(surface)
     218        surface.blit(self._tiled, self._offset)
    217219        super(TiledRenderer, self).render(surface)
Note: See TracChangeset for help on using the changeset viewer.