Scale Everything On Pygame Display Surface

后端 未结 1 480
不知归路
不知归路 2021-01-26 23:46

So I\'m making a 2D pixel art game in pygame and as you could assume, all my sprite textures appear very small. I\'m wondering if there\'s a way I can globally scale everything

相关标签:
1条回答
  • 2021-01-27 00:11

    I'm wondering if there's a way I can globally scale everything up in my game without either having to scale each sprite up individually [...]"

    No there is no way. You have to scale each coordinate, each size and each surface individually. PyGame is made for images (Surfaces) and shapes in pixel units. Anyway up scaling an image will result in either a fuzzy, blurred or jagged (Minecraft) appearance.

    Is there a way I could make a separate surface and just put that on top of the base window surface, and just scale that?

    Yes of course.

    Create a Surface to draw on (win). Use pygame.transform.scale() or pygame.transform.smoothscale() to scale it to the size of the window and blit it to the actual display Surface (display_win):

    display_win = pygame.display.set_mode((WINDOW_WIDTH*2, WINDOW_HEIGHT*2))
    win = pygame.Surface((WINDOW_WIDTH, WINDOW_HEIGHT))
    
    while running:
        # [...]
    
        if not paused:
            win.fill(COL_BG)
            all_sprites.update()
            all_sprites.draw(win)
    
        # [...]
    
        scaled_win = pygame.transform.smoothscale(win, display_win.get_size())
        # or scaled_win = pygame.transform.scale(win, display_win.get_size())
        display_win.blit(scaled_win, (0, 0))
        pygame.display.flip()
    

    Minimal example: repl.it/@Rabbid76/PyGame-UpScaleDisplay

    0 讨论(0)
提交回复
热议问题