【问题标题】:Pygame - What happens if you blit a surface with a rect smaller than the surface?Pygame - 如果你用比表面小的矩形来对表面进行 blit 会发生什么?
【发布时间】:2013-12-17 03:00:39
【问题描述】:

在这个blit 电话中

screen = pygame.Surface(640, 480)
bgsurf = pygame.Surface(640, 480)
new_rect = pygame.Rect(0, 0, 80, 80)

screen.blit(bgsurf, new_rect, new_rect)

pygame 如何决定将bgsurf 的哪一部分复制到new_rect 区域的屏幕上?

【问题讨论】:

    标签: python pygame rect


    【解决方案1】:

    来自 pygame 文档:

    blit(source, dest, area=None, special_flags = 0) -> 矩形

    在此 Surface 上绘制源 Surface。抽奖可以定位 与 dest 论点。 Dest 可以是一对坐标 代表源的左上角矩形也可以 作为目的地传递,矩形的左上角将 用作 blit 的位置。 目标的大小 矩形不影响 blit。

    也可以传递一个可选的区域矩形。这代表了一个 要绘制的源 Surface 的较小部分。

    如您所见,pygame 会在 (0,0) 处对整个表面进行 blit。 如果要对表面的一部分进行blit,则需要传入区域Rect。

    编辑:

    在您的情况下,它将把 new_rect 给出的次表面粘贴到屏幕上,左上角将放置在 (0,0) 处。

    【讨论】:

      猜你喜欢
      • 2017-01-04
      • 2020-08-07
      • 1970-01-01
      • 1970-01-01
      • 2015-08-15
      • 2016-01-23
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      相关资源
      最近更新 更多