Bowen Kuang
Bowen Kuang

Reputation: 100

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(self.data.boundary_polygon_list)
    pygame.draw.polygon(self.screen, BLUE, boundary, LINEWIDTH)

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

    # draw agents
    self._executeSegment(self.agentsGroup.sprites()[0],(5,10),ticks)
    for agent in self.agentsGroup:
        pygame.draw.circle(self.screen, WHITE, agent.rect.center, self.data.sensor_range * self.scaleForMap,LINEWIDTH)

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

Upvotes: 1

Views: 441

Answers (1)

Ari Cooper-Davis
Ari Cooper-Davis

Reputation: 3485

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) )

Upvotes: 3

Related Questions