# HG changeset patch # User Neil Muller # Date 1252322452 0 # Node ID b4ead8d2b7768184a5e39e5340ae381b737ec844 # Parent 7bcdfb190f33f0cb122e0c82040768b577fb6d43 Add bounds checking to animation drawing loop diff -r 7bcdfb190f33 -r b4ead8d2b776 gamelib/gameboard.py --- a/gamelib/gameboard.py Sun Sep 06 23:55:49 2009 +0000 +++ b/gamelib/gameboard.py Mon Sep 07 11:20:52 2009 +0000 @@ -271,8 +271,11 @@ us = [] x, y = self.vid.view.x, self.vid.view.y for anim in self.gameboard.animations[:]: - if anim.updated or anim.removed: + if (anim.updated or anim.removed) and \ + self.gameboard.in_bounds(anim.pos): # We flag that we need to redraw stuff undeneath the animation + anim.irect.x = anim.rect.x - anim.shape.x + anim.irect.y = anim.rect.y - anim.shape.y us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y, anim.irect.width, anim.irect.height)) self.vid.alayer[anim.pos.y][anim.pos.x]=1 @@ -282,15 +285,12 @@ self.gameboard.animations.remove(anim) us.extend(self.vid.update(surface)) for anim in self.gameboard.animations: - if anim.updated: - anim.fix_pos(self.vid) + if anim.updated: # setimage has happened, so redraw - anim.irect.x = anim.rect.x - anim.shape.x - anim.irect.y = anim.rect.y - anim.shape.y - surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y)) anim.updated = 0 - us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y, - anim.irect.width, anim.irect.height)) + anim.fix_pos(self.vid) + if self.gameboard.in_bounds(anim.pos): + surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y)) # This is enough, because sprite changes happen disjoint # from the animation sequence, so we don't need to worry # other changes forcing us to redraw the animation frame.