代码之家  ›  专栏  ›  技术社区  ›  Aemyl

在pygame中禁用抗锯齿

  •  1
  • Aemyl  · 技术社区  · 5 年前

    我尝试在pygame中使用 pygame.PixelArray

    import pygame
    
    
    BLACK = (0, 0, 0)
    BLUE  = (0, 0, 255)
    WHITE = (255,255,255)
    
    
    class GUI:
    
        def __init__(self):
    
            self.screen = pygame.display.set_mode((300, 300))
            pygame.mouse.set_visible(True)
            self.clock = pygame.time.Clock()
    
        def gameloop(self):
    
            running = True
            while running:
                self.screen.fill(WHITE)
                # event handling
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        running = False
                # drawing
                # for some reason, everything gets anti-aliased
                pixel_array = pygame.PixelArray(self.screen)
                pixel_array[100][100] = BLACK
                pixel_array[100][101] = BLUE
                pixel_array[101][100] = BLUE
                pixel_array[101][101] = BLACK
                del pixel_array
                # update full display
                pygame.display.flip()
                self.clock.tick(30)
    
    
    def main():
    
        pygame.init()
        gui = GUI()
        gui.gameloop()
        pygame.quit()
    
    
    if __name__ == '__main__':
    
        main()
    

    我得到的是:

    anti-aliased pixels

    我期望得到的是:

    pixels

    Python版本:3.7.2(64位)
    操作系统:Windows 10家庭版1803版本17134.590

    显示器:集成在联想笔记本电脑中(1920 x 1080)


    0 回复  |  直到 5 年前
        1
  •  2
  •   Aemyl    5 年前

    在得到一个暗示之后 Eric ,我发现问题不是由pygame引起的,而是由显示器分辨率设置引起的。默认情况下,显示比例为125%。

    settings settings2