comparison gamelib/gameboard.py @ 234:ee1ac134022d

Fix drawing bug with multiframe animations
author Neil Muller <drnlmuller@gmail.com>
date Sat, 05 Sep 2009 09:23:11 +0000
parents 0bd214cf9018
children 1a7097c0fc8f
comparison
equal deleted inserted replaced
233:d3d5352f5853 234:ee1ac134022d
161 161
162 def update(self, surface): 162 def update(self, surface):
163 us = [] 163 us = []
164 x, y = self.vid.view.x, self.vid.view.y 164 x, y = self.vid.view.x, self.vid.view.y
165 for anim in self.gameboard.animations[:]: 165 for anim in self.gameboard.animations[:]:
166 # We process removed animations 1st, so we redraw things correctly 166 if anim.updated or anim.removed:
167 if anim.removed: 167 # We flag that we need to redraw stuff undeneath the animation
168 us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y, 168 us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y,
169 anim.irect.width, anim.irect.height)) 169 anim.irect.width, anim.irect.height))
170 self.gameboard.animations.remove(anim)
171 # Flag the underlying tiles/sprites to be redrawn
172 self.vid.alayer[anim.pos.y][anim.pos.x]=1 170 self.vid.alayer[anim.pos.y][anim.pos.x]=1
173 self.vid.updates.append(anim.pos.to_tuple()) 171 self.vid.updates.append(anim.pos.to_tuple())
172 if anim.removed:
173 # Remove the animation from the draw loop
174 self.gameboard.animations.remove(anim)
174 us.extend(self.vid.update(surface)) 175 us.extend(self.vid.update(surface))
175 for anim in self.gameboard.animations: 176 for anim in self.gameboard.animations:
176 if anim.updated: 177 if anim.updated:
177 anim.fix_pos(self.vid) 178 anim.fix_pos(self.vid)
178 # setimage has happened 179 # setimage has happened, so redraw
179 anim.irect.x = anim.rect.x - anim.shape.x 180 anim.irect.x = anim.rect.x - anim.shape.x
180 anim.irect.y = anim.rect.y - anim.shape.y 181 anim.irect.y = anim.rect.y - anim.shape.y
181 surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y)) 182 surface.blit(anim.image, (anim.irect.x - x, anim.irect.y - y))
182 anim.updated = 0 183 anim.updated = 0
183 us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y, 184 us.append(pygame.Rect(anim.irect.x - x, anim.irect.y - y,
184 anim.irect.width, anim.irect.height)) 185 anim.irect.width, anim.irect.height))
186 # This is enough, because sprite changes happen disjoint
187 # from the animation sequence, so we don't need to worry
188 # other changes forcing us to redraw the animation frame.
185 return us 189 return us
186 190
187 def move_view(self, x, y): 191 def move_view(self, x, y):
188 self.vid.view.move_ip((x, y)) 192 self.vid.view.move_ip((x, y))
189 193