英文:
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)))
英文:
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)))
答案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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论