[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Problem with basics
Adrian wrote:
> Hi all. Ok, here's the problem. I'm starting all over with my project (a
> bubble puzel game) but now that I'm using classes and the sprite module
> I can't get my game objects to show up in the screen. my code is here:
hello adrian. i just looked over the code. you've got it all running 99%
correctly. too bad it's that last 1% keeping us from seeing anything.
the problem is, there are no sprites inside the "render" group. this is
pretty easy to fix, and there are two main ways to do it. i see a lot of
the "chimp" example in here, so there's only one small change needed to
make it work like chimp.
the sprite objects in the chimp tutorial keep a class variable of all
the groups each type of sprite should belong to. you also do this in
your code with:
Gun.containers = render
Bubble.containers = render
the thing you're missing is passing this value to the sprites when you
call the Sprite.__init__ function. for example, change the line in
Gun.__init__ to:
pygame.sprite.Sprite.__init__(self, Gun.containers)
do the same for Bubble, and the sprites will be added to the group when
they are instanced. currently it seems you only have one sprite group,
so you could just make "render" a global, and pass that when you call
Sprite.__init__? but if you start adding more groups, your current way
is more flexible.
also remember you can easily add and remove sprites from groups with the
add() and remove() methods in each class.
heh, there's a couple other little things, but i'm sure you'll get those
cleaned up quick once you can "see" what's going on :]
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org