Anyone here use Python's Pygame library?

Onionsoilder

Reaver
Joined
Mar 19, 2007
Messages
3,173
So I'd decided to pick up Python over the summer so I could begin working on app development for android phones. After getting the basics down, my first project was making a simple adventure roguelike game using the Pygame library, and I'm having problems with the pygame graphics I can't work out.

Basing my game off of tutorials and example code, I've got everything working so far except rendering the sprites(or sprite, more accurately. At this point I only have the player in the game). I can render him to the screen just fine, but the problem is when I move him - he gets rendered at his new location, but doesn't stop being rendered where he was previously. So when he moves, he leaves a trail of himself behind.

Anyone know how to fix this? I could just re-render the entire background to cover the old sprites up, but that seems horribly inefficient, and since I plan on porting this to android once I'm finished with it, I don't want to do any computations I don't need.
 
Have you defined a background?

Code:
self.background = pygame.Surface(self.screen.get_size())
self.background = self.background.convert()
self.background.fill((0,0,0))

Then just blit it to the screen like so inside the main loop.

Code:
self.screen.blit(self.background, (0,0))

That just makes a black background, but it totally fixes the exact issue you are encountering. However, I would suggest Java for Android, as far as I'm aware it has a ton more support in the community.
 
Yeah, the background was defined - the problem is my background isn't just an image, but a set of tiles which were rendered to the screen. So, while I could do that, I would need to run through all of my arrays and re-render every single sprite.

I did end up with a fix though, which involves re-rendering the player's tile before he moves with just the background, then moving and rendering the player's sprite on the new tile.
 
Back
Top Bottom