Pygame的display.update()刷新整个窗口的宽度,而不仅仅是请求的矩形部分。

huangapple go评论62阅读模式
英文:

Pygame display.update() refreshes the whole width of window instead of requested Rect only

问题

I'm discovering Pygame and stuck on some problematic behavior that I can't figure out.

我正在探索Pygame,并遇到了一些问题行为,我无法弄清楚。

I am trying to refresh a 80px square in the center of the window with the code below, but the whole line turns blue instead of the square only as expected. Is this normal behavior, and can someone help me understand why this is happening please?

我试图使用下面的代码在窗口中央刷新一个80像素的正方形,但是整条线变成蓝色,而不是像预期的那样只有正方形。这是正常行为吗?有人能帮助我理解为什么会发生这种情况吗?

Using pygame 2.1.3 / python 3.11.1 / macOS 13.1

使用 pygame 2.1.3 / python 3.11.1 / macOS 13.1

import pygame
pygame.init()
screen = pygame.display.set_mode((400, 400))
screen.fill((255,0,0))
pygame.display.update(((160,160,80,80)))

Pygame的display.update()刷新整个窗口的宽度,而不仅仅是请求的矩形部分。

英文:

I'm discovering Pygame and stuck on some problematic behavior that I can't figure out.

I am trying to refresh a 80px square in the center of the window with the code below, but the whole line turns blue instead of the square only as expected. Is this normal behavior, and can someone help me understand why this is happening please?

Using pygame 2.1.3 / python 3.11.1 / macOS 13.1

import pygame
pygame.init()
screen = pygame.display.set_mode((400, 400))
screen.fill((255,0,0))
pygame.display.update(((160,160,80,80)))

Pygame的display.update()刷新整个窗口的宽度,而不仅仅是请求的矩形部分。

答案1

得分: 3

The documentation for pygame.display.update() does not clearly specify that, however the rectangle is not intended to limit the screen update to that area, but at least to update that area in the most efficient way. What method is most efficient may depend on the system. Note that the window is organized in lines, so it may be more efficient to update a complete set of contiguous lines than to update many line sections separately.

Use pygame.Surface.set_clip() to restrict the modifieable surface to a certain area:

screen.set_clip((160,160,80,80))
screen.fill((255,0,0))
pygame.display.update()
英文:

The documentation for pygame.display.update() does not clearly specify that, however the rectangle is not intended to limit the screen update to that area, but at least to update that area in the most efficient way. What method is most efficient may depend on the system. Note that the window is organized in lines, so it may be more efficient to update a complete set of contiguous lines than to update many line sections separately.

Use pygame.Surface.set_clip() to restrict the modifieable surface to a certain area:

screen.set_clip((160,160,80,80))
screen.fill((255,0,0))
pygame.display.update()

huangapple
  • 本文由 发表于 2023年2月24日 02:02:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定