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

[pygame] Re:



class basicsprite(pygame.sprite.Sprite): #create a sprite class
   def __init__(self, img):
       pygame.sprite.Sprite.__init__(self) #You need to init the sprite class ;-)
       self.image = pygame.image.load(img).convert_alpha()
       self.rect = self.image.get_rect()


On Sun, Jan 11, 2009 at 9:12 AM, Yanom Mobis <yanom@xxxxxxxxxxxxxx> wrote:
Ok, this is weird:

#init-code

import sys, pygame, os, namegen
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (100, 100)
from pygame.locals import *
screen = pygame.display.set_mode((500, 500),pygame.NOFRAME)
clock = pygame.time.Clock()
bgc = 0, 255, 2

class basicsprite(pygame.sprite.Sprite): #create a sprite class
   def __init__(self, img):
       self.image = pygame.image.load(img).convert_alpha()
       self.rect = self.image.get_rect()

#make a canister
spritecan = pygame.sprite.Group()


redcar = basicsprite("redcar.png")
spritecan.add(redcar)
#ready... set... GO!!!

while True: #main loop
   clock.tick(30)
   for event in pygame.event.get(): #every game has one
       if event.type == QUIT:
           exit()
       if event.type == KEYDOWN and event.key == K_ESCAPE:
           exit()
   screen.fill(bgc)
   spritecan.draw(screen)
   pygame.display.flip()



gives this error:


/usr/bin/python -u  "/home/yanom/app/game/game.py"
Traceback (most recent call last):
 File "/home/yanom/app/game/game.py", line 20, in <module>
   spritecan.add(redcar)
 File "/usr/lib/python2.5/site-packages/pygame/sprite.py", line 319, in add
   sprite.add_internal(self)
 File "/usr/lib/python2.5/site-packages/pygame/sprite.py", line 147, in add_internal
   self.__g[group] = 0
AttributeError: 'basicsprite' object has no attribute '_Sprite__g'









--
- pymike
"Python eggs me on."