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

Re: [pygame] BUG: pygame.sprite.GroupSingle does not work



Thanks for the patch.

It has been applied to cvs.

Cheers.

On 1/30/06, Alexander Sashnov <asashnov@xxxxxxxxxx> wrote:
> Hi all,
>
> seems there are bug in pygame.sprite.GroupSingle (platform independed,
> present in current CVS version).
>
> Here my example (test) for this bug:
>
>
> #! /usr/bin/env python
>
> import pygame
>
> from pygame.locals import *
>
> # modified functions from chimp.py example
> def load_image(name, colorkey=None):
>     fullname = name
>     try:
>         image = pygame.image.load(fullname)
>     except pygame.error, message:
>         print 'Cannot load image:', fullname
>         raise SystemExit, message
>     image = image.convert()
>     if colorkey is not None:
>         if colorkey is -1:
>             colorkey = image.get_at((0,0))
>         image.set_colorkey(colorkey, RLEACCEL)
>     return image, image.get_rect()
>
>
> class Player(pygame.sprite.Sprite):
>     def __init__(self):
>         pygame.sprite.Sprite.__init__(self)
>         self.image, self.rect = load_image("player.png")  # any image here
>
>
> pygame.init()
>
> screen = pygame.display.set_mode((640, 480))
>
> playerGroup = pygame.sprite.GroupSingle()
>
> p = Player()
>
> playerGroup.add(p)
>
> clock = pygame.time.Clock()
>
> while 1:
>     clock.tick(60)
>
>     #Handle Input Events
>     for event in pygame.event.get():
>         if event.type == QUIT:
>             break
>
>     playerGroup.draw(screen)   # Oop! 'GroupSingle' object has no attribute 'spritedict'.
>
>     pygame.display.flip()
>
>
>
> Here the traceback of trying execute it:
>
> alex$ python singlegroup.py
> Traceback (most recent call last):
>   File "singlegroup.py", line 50, in ?
>     playerGroup.draw(screen)
>   File "/usr/lib/python2.3/site-packages/pygame/sprite.py", line 313, in draw
>     self.spritedict[spr] = surface_blit(spr.image, spr.rect)
> AttributeError: 'GroupSingle' object has no attribute 'spritedict'
>
>
>
> Seems forgotten call parent constructor in class GroupSingle:
>
> alex$ diff -Naur pygame.orig/ pygame
> diff -Naur pygame.orig/lib/sprite.py pygame/lib/sprite.py
> --- pygame.orig/lib/sprite.py   2006-01-30 14:03:26.000000000 +0600
> +++ pygame/lib/sprite.py        2006-01-30 14:05:34.000000000 +0600
> @@ -430,6 +430,7 @@
>         sprite and then add the new one."""
>
>      def __init__(self, sprite = None):
> +        AbstractGroup.__init__(self)
>          self.__sprite = None
>          if sprite is not None: self.add(sprite)
>
>
> After patch image will displayed.
>
> --
> Alexander Sashnov
> ICQ UIN: 79404252
> JID: asashnov@xxxxxxxxx
>
>