Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pygame更新显示_Python_Pygame - Fatal编程技术网

Python Pygame更新显示

Python Pygame更新显示,python,pygame,Python,Pygame,我正在写一个程序,其中传感器(白色圆圈)在地图上移动以覆盖物体。我数了一下覆盖物的数量(小白点),这是正确的数字。但是屏幕上仍然有旧的覆盖物和传感器(白色圆圈)。如何更新显示,使屏幕上只显示最新的对象(圆圈路径中不应显示红点,且不应显示圆圈路径历史记录) 这是我的显示代码。它每帧都会被调用 def _drawMap(self,ticks): # draw the map # draw the boundary boundary = self._polygonCoo

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

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

    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)

在pygame中,你不能清除屏幕-相反,你可以将背景重新放到当前屏幕的上方

同样的问题有一个很好的答案

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

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

在pygame中,你不能清除屏幕-相反,你可以将背景重新放到当前屏幕的上方

同样的问题有一个很好的答案

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

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

非常感谢。我把它作为第一行函数添加到问题中,现在它工作正常了。谢谢!我在问题中添加了这个函数作为第一行,现在它工作正常了。