pygame如何修复“尾像素”? [英] Pygame how to fix 'trailing pixels'?

查看:63
本文介绍了pygame如何修复“尾像素”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在image红色轨迹是pygame在精灵周围添加边框时创建的轨迹。 Sprite也会这样做,最简单的解决方案是在每次重绘后将表面清除为黑色。但是,尝试在整个主表面上这样做并不是一个好主意。我该如何解决?

In the image the red trail is a trail that pygame is creating when I have a bounding rectangle added around sprites. The sprite also does it and the simplest solution was to just clear the surface to black after each redraw. However attempting to do so on the entire main surface is not such a good idea. How can I fix this?

推荐答案

通常,您会这样做:

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

但是,您可以仅更新屏幕的脏部分。请参阅 pygame。 display.update()

But, you can update just dirty portions of the screen. See pygame.display.update():


pygame.display.update()

更新屏幕部分以显示软件

update(rectangle = None)->无

update(rectangle_list)->无

此功能类似于pygame.display.flip()的优化版本,用于软件显示。它只允许屏幕
的一部分更新,而不是整个区域。如果没有传递参数
,它将更新整个Surface区域,如
pygame.display.flip()。

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

您可以将函数传递给单个函数矩形或一系列矩形。与
一次传递多个矩形相比,使用
矩形的单个或部分列表多次调用update更为有效。如果传递一系列矩形,则可以安全地在列表中包括
None值,该值将被跳过。

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

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


pygame.sprite.RenderUpdates

跟踪脏更新的组子类。

RenderUpdates(* sprites)-> RenderUpdates

此类源自pygame.sprite.Group()。它具有扩展的draw()方法,可跟踪屏幕的更改区域。

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如何修复“尾像素”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆