Bowen Kuang Bowen Kuang - 11 months ago 75
Python Question

Pygame update display

I am writing a program where sensors(the white circles) are moving on the map to cover things. I counted the number of covered things(the small white dots), it's the right number. But the old covered things and sensor(white circles) are still on the screen. How can I update the display so that only newest objects are on the screen(no red dots should be in the circle path, and the circle path history should not be displayed).My display

Here is my display code. It gets called every frame.

def _drawMap(self,ticks):
# draw the map
# draw the boundary
boundary = self._polygonCoordinationTransformation(
pygame.draw.polygon(self.screen, BLUE, boundary, LINEWIDTH)

# draw obstacles
for polygon in
polygon = self._polygonCoordinationTransformation(polygon)
pygame.draw.polygon(self.screen, BLUE, polygon, LINEWIDTH)

# draw agents
for agent in self.agentsGroup:, WHITE,, * self.scaleForMap,LINEWIDTH)

# draw items
for itemObj in self.unseenItemGroup:
pygame.draw.rect(self.screen, RED, itemObj, LINEWIDTH)

Answer Source

In pygame you can't clear the screen - instead you re-blit the background back over the top of what is currently there.

There's an excellent answer to the same question here.

Edit: In your case you probably want to fill the screen in with black:

screen.fill( (0,0,0) )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download