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

Re: [pygame] split newbie strikes back



Mundial 82 wrote:
> Following your wise advice, I have used the split screen technique that
> Casey wrote about, and everything worked great ... until I tried to
> create sprites that spawned on the bottom screen, to which it politely
> refuses. All the sprites are instantiated in the top screen, and I have
> no idea why (I think it's because this subsurface method creates a child
> of the top_screen, and then when assigning random positions, it all gets
> messed up).

        playerTop.draw(screen)
        playerBot.draw(screen)
        topPoints.draw(screen)
        botPoints.draw(screen)

Try changing to:

playerTop.draw(top_screen)
playerBot.draw(bot_screen)
topPoints.draw(top_screen)
botPoints.draw(bot_screen)

etc.

Also, your check_bounds for the Square class doesn't make sense. The
purpose of using subsurfaces is that you don't have to worry about
"where" the sprite.rect is relative to the parent surface, only the
child surface. I changed that to this:

    def checkBounds(self):
        if self.rect.centerx > self.screen.get_width():
            self.rect.centerx = 0
        if self.rect.centerx < 0:
            self.rect.centerx = self.screen.get_width()
        if self.rect.centery > self.screen.get_height():
            self.rect.centery = 0
        if self.rect.centery < 0:
            self.rect.centery = self.screen.get_height()

I'd be a little wary of blending your sprite-drawing code and your
physics code like this, though.

Hope this helps!

Ethan

Attachment: signature.asc
Description: OpenPGP digital signature