0
\$\begingroup\$

I have a problem using spritegroups in pygame. In my situation I have 2 spritegroups, one for humans, one for "infected". A human is represented by a blue circle:

image = pygame.Surface((32,32))
image.fill((255,255,255))
pygame.draw.circle(image,(0,0,255),(16,16),16)
image = image.convert()
image.set_colorkey((255,255,255))

An infected by a red one (same code, different color).

I update my spritegroups as follows:

 self.humans.clear(self.screen, self.bg)
 self.humans.update(time_passed)
 self.humans.draw(self.screen)

 self.infected.clear(self.screen, self.bg)
 self.infected.update(time_passed)
 self.infected.draw(self.screen)

Self.bg is defined:

self.bg = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT))
self.bg.fill((255,255,255))
self.bg.convert()

This all works, except that when a red circle overlaps with a blue one, you can see the white corners of the bounding box around the actual circle. Within a spritegroup it works, using the set_colorkey function. This does not happen with overlapping blue circles or overlapping red circles.

I tried adding a colorkey to self.bg but that did not work. Same for adding a colorkey to self.screen.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Can you post a screenshot? \$\endgroup\$
    – muhuk
    Feb 2, 2012 at 1:58

2 Answers 2

1
\$\begingroup\$

This is not the problem with colorkey. When you clear the sprites from the second group, you erase parts of the sprites from the first group that were already drawn. To fix it, change the order of clearing and drawing:

self.infected.clear(self.screen, self.bg)
self.humans.clear(self.screen, self.bg)

self.humans.update(time_passed)
self.humans.draw(self.screen)

self.infected.update(time_passed)
self.infected.draw(self.screen)
\$\endgroup\$
0
\$\begingroup\$

Im new enough to python so I may be completely wrong but would it work if you put in pygame.display.flip()

Thats what I have in my game after it is drawn and updated on the screen?

\$\endgroup\$
1
  • \$\begingroup\$ Nah, is not necessary here :-). (It's not all my code by the way ;)) \$\endgroup\$
    – Kevin
    Feb 1, 2012 at 18:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .