python - Pygame 1.9.3: Adding sprite (without class) to a group -


so ok, have things in game (player, boss, levelgoal...) need exist in 1 instance @ given time, , simplify code letting these things manually-declared sprites--rather first existing classes need instantiated objects.

(many it's best group classes anyway, whether or not agree that--it'd useful know way around in case.)

i have sprites in groups though, purposes of hit-detection (and being drawn onto screen). i'm having issue this, however. thought pretty simple make isolated, "classless" sprite , add list.

blooblist = pygame.sprite.group()  blooby = pygame.sprite.sprite  blooby.image = pygame.surface([200,200]) blooby.image.fill([0,0,0]) blooby.rect = blooby.image.get_rect()  blooblist.add(blooby) 

when running however, application crashes upon launching. ide opens sprite.py pygame library, takes me line 378 , tells me:

builtins.typeerror: add_internal() missing 1 required positional argument: 'group' 

i've googled around looking means , found no answers. check myself, wrote class+object+group adding scenario in exact same program:

moochlist = pygame.sprite.group()  class mooch(pygame.sprite.sprite):     def __init__(self):         pygame.sprite.sprite.__init__(self)         self.image = pygame.surface([200,200])         self.image.fill([0,0,0])         self.rect = self.image.get_rect()  stootch = mooch()  moochlist.add(stootch) 

and 1 worked usual. checked pygame.org's documentation , don't think said sprite must object spawned class in order added group, didn't "classless" sprites allowed either.

i'm brand new pygame mind you, expect realize missing obvious here, leads me assume classless sprites should allowed groups group.add function only concerns specific sprite named , group itself--with no mention of class sprite belongs to.

the error occurs because try add pygame.sprite.sprite class group instead of instance. added parentheses, create instance/object, should work correctly:

blooby = pygame.sprite.sprite() 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -