[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] BUG: pygame.sprite.GroupSingle does not work
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] BUG: pygame.sprite.GroupSingle does not work
- From: "Rene Dudfield" <renesd@xxxxxxxxx>
- Date: Sat, 11 Mar 2006 19:37:05 +1100
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sat, 11 Mar 2006 03:37:12 -0500
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=WBvrKLnpghfvI5+pNUvZ5qEkgShzSCDzUzVGRBb8NbjMp9UwMycSeEWjOYt0gc/oopNZ1VxfZuFSoO3lSDkqLVXaj2z85fas9P93FYDuMr1XCmGkz2VjjB8bmlbPKyX9CSPyqqTqVK1AHsk3NQFl6jhwtxGzpfeXYWyzUBz3JHM=
- In-reply-to: <87bqxujagf.fsf@sashnov.plesk.ru>
- References: <87bqxujagf.fsf@sashnov.plesk.ru>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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
>
>