Yoshow2137
Yoshow2137

Reputation: 31

Pygame zooming screen

im writing a game right now with 32x32 textures, i have a problem because my screen window is too small, is there any solution? Can i "zoom" my whole game?enter image description here

Now it looks like this and exactly what i want is to make whole screen bigger and zoom to see only like 5% of map.

Of course, if i make my screen bigger it not gonna fix my problem. Maybe i should add another camera or something? enter image description here

I think I made myself quite clear. Thanks!

Upvotes: 0

Views: 1339

Answers (2)

Yamm Elnekave
Yamm Elnekave

Reputation: 66

First, you can definitely zoom as you are saying.

screen.blit(pygame.transform.scale(display, (int(width), int(height)))

You can resize the screen:

screen = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT),pygame.RESIZABLE)
def resize(event):
    global WINDOWWIDTH, WINDOWHEIGHT
    if event.type == pygame.VIDEORESIZE:
        WINDOWWIDTH = event.size[0]
        WINDOWHEIGHT = event.size[1]
        return pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), pygame.RESIZABLE)

And have the display the actual size you want to draw to:

display = pygame.Surface((300,200))

However, scaling surfaces is really bad as pixel art isn't great at scaling. An alternative would be a camera or switching off of pygame which would make everything you are trying to do way less complicated. I would recommend rubato for a start. It will do all this work for you, and you can decide how big you want your actual grid (display) to be with one variable.

Good luck! Feel free to comment if you want any extra help.

Upvotes: 1

jake is the coolest
jake is the coolest

Reputation: 99

One way you can fix this is by shrinking the size of the screen itself:

#you can adjust the width and height in game until it seems the right fit
screen=pygame.display.set_mode((WIDTH,HEIGHT))

And if you want, you can set the window to Fullscreen:

screen=pygame.display.set_mode((WIDTH,HEIGHT),pygame.FULLSCREEN)

Upvotes: -1

Related Questions