gpt4 book ai didi

Pygame 如何修复 'trailing pixels' ?

转载 作者:行者123 更新时间:2023-12-01 22:53:37 29 4
gpt4 key购买 nike

enter image description here

在图像中,红色轨迹是当我在 Sprite 周围添加了一个边界矩形时 pygame 创建的轨迹。 Sprite 也这样做,最简单的解决方案是在每次重绘后将表面清除为黑色。然而,尝试在整个主表面上这样做并不是一个好主意。我该如何解决这个问题?

最佳答案

通常你会这样做:

def draw():
# fill screen with solid color.
# draw, and flip/update screen.

但是,您可以只更新屏幕的脏部分。参见 pygame.display.update() :

pygame.display.update()
Update portions of the screen for software displays
update(rectangle=None) -> None
update(rectangle_list) -> None

This function is like an optimized version of pygame.display.flip() for software displays. It allows only a portionof the screen to updated, instead of the entire area. If no argumentis passed it updates the entire Surface area likepygame.display.flip().

You can pass the function a single rectangle, or a sequence of rectangles. It is more efficient to pass many rectangles at once thanto call update multiple times with single or a partial list ofrectangles. If passing a sequence of rectangles it is safe to includeNone values in the list, which will be skipped.

最好与RenderUpdates结合使用,这是一个 Sprite.Group:

pygame.sprite.RenderUpdates
Group sub-class that tracks dirty updates.
RenderUpdates(*sprites) -> RenderUpdates
This class is derived from pygame.sprite.Group(). It has an extended draw() method that tracks the changed areas of the screen.

关于Pygame 如何修复 'trailing pixels' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6487538/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com