Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
1  
Can you post a screenshot? –  muhuk Feb 2 '12 at 1:58

2 Answers 2

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)
share|improve this answer

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?

share|improve this answer
    
Nah, is not necessary here :-). (It's not all my code by the way ;)) –  Fristi Feb 1 '12 at 18:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.