[Tutor] Moveable and Animated Sprites

Alan Gauld alan.gauld at btinternet.com
Mon Aug 15 09:00:41 CEST 2011


On 15/08/11 03:09, Jordan wrote:
> Is there a more Pythonic way to create the class
> "MoveableAnimatedSheetSprite" I am using multiple inheritance but I see
> that I am really loading the image twice when I call __init__ for
> "AnimatedSheetSprite" and "MoveableSprite". Should I just make a
> moveable class and have moveable items inherit it with out inheriting
> from "Sprite"?

This is really more a pyGame question than a Python one so you will
probably get a better response posting on the PyGame forum.
However there are a few pyGamers here so you might get lucky...

> class Sprite(pygame.sprite.Sprite):
>      def __init__(self, imageName, startx=0, starty=0):
>          pygame.sprite.Sprite.__init__(self)
>          self.image=pygame.image.load(imageName)
>          self.rect=self.image.get_rect()
>          self.image.convert()
>          self.x=startx
>          self.y=starty
>          self.position=vec2d(self.x,self.y)
>          self.selected=False
>
>      def update(self):
>          pygame.sprite.Sprite.update(self)
>

If you are just calling the superclass you don't need this method.
But I assume you will be adding extra content later? If not, your
subclasses can still call Sprite.update() without this definition being
here.

Beyond that I can't add much...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list