Hi,
I have small but annoying problem with my sprite
code. I have made my own class for an animated sprite. It works by loading an
image containing all of the animation's frames and then displays each frame
in order. I'm accomplishing this by passing an area rect to blit().
Here's some code:
def
draw(self):
if not self.bHide: self.screen.blit(self.surf, self.rect, self.frect) self.step() def
step(self):
if not self.paused: if self.timelaps >= self.animrate: if self.frame == self.numframes-1: self.frame = 0 else: self.frame += 1 self.timelaps = 0 self.timelaps += self.hostapp.clock.getFrameDuration() self.frect = self.getFrameRect(self.frame) def getFrameRect(self,
fnum):
fcx = self.frameulcoords[fnum][0] fcy = self.frameulcoords[fnum][1] r = self.surf.get_rect(topleft=(fcx, fcy), width=self.fw, height=self.fh) return r These are methods of the sprite class. In my
application's update method I have this to move the sprite with the arrow
keys:
if self.goup and not
self.godown:
self.s.move((0,-300*self.clock.getFrameDuration())) elif self.godown and not self.goup: self.s.move((0,300*self.clock.getFrameDuration())) The problem I'm experiencing is that when I move
the sprite around I get parts of the other frames showing nastily, like the
frame above the sprite's current frame or the one to the left of it. Let me know
if I'm doing something wrong. I'm not totally sure I should be using blit's area
rect for changing the animation's frames.
Thanks
Juha Salo
|