[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Odd problem with lists



What the heck are you doing copying images during your animation? 
Forget that, it's wasteful and overcomplicated.

1.  Make a list of images.
2. For each animation sequence (for example walking_left and
walking_right), make a list or tuple of indices in your list of images
(i.e. walking_left=(0,1,2,3)) that correspond to the cels in that
animation.
3.When the character state is (for example, walking to the left), then
anim_loop = walking_left.
4.You have a loop that every few cycles increments the animation
counter.  Then player.image = anim_loop[animation_counter]

or... as in my code

if self.moving:
        if self.frame_delay == DELAY:
                self.frame_delay = 0
                if self.frame_cel == len(self.current_strip)-1:
                    self.frame_cel = 0
                else:
                    self.frame_cel += 1
        else:
                self.frame_delay += 1

        if self.y_direction == up:
            self.current_strip = self.up_strip
                
        elif self.y_direction == down:
                self.current_strip = self.down_strip         
            
        if self.x_direction == left:
                self.current_strip = self.left_strip
            
        elif self.x_direction == right:
                self.current_strip = self.right_strip
         

        self.image =
self.cel_group[self.current_strip[self.frame_cel]]


That should do you.
-- 
Andrew Ulysses Baker
"failrate"