【问题标题】:Pygame update displayPygame更新显示
【发布时间】:2017-03-11 23:24:55
【问题描述】:

我正在编写一个程序,其中传感器(白色圆圈)在地图上移动以覆盖事物。我数了数被覆盖的东西(小白点)的数量,这是正确的数字。但旧的覆盖物和传感器(白色圆圈)仍在屏幕上。如何更新显示,以便屏幕上只有最新的对象(圆圈路径中不应出现红点,并且不应显示圆圈路径历史)。

这是我的显示代码。每帧都会调用它。

    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)

【问题讨论】:

    标签: python pygame


    【解决方案1】:

    在 pygame 中,您无法清除屏幕 - 相反,您将背景重新设置为当前存在的顶部。

    对于同一个问题here,有一个很好的答案。

    编辑:在您的情况下,您可能希望用黑色填充屏幕:

    screen.fill( (0,0,0) )
    

    【讨论】:

    • 谢谢!我将它添加为 qustion 中的第一行函数,现在它可以正常工作了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-14
    • 1970-01-01
    • 2023-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多