Reputation: 31
How can I get the size of the actual display, without using event.dict['size']
?
Suppose I have a game with two screens, 'Menu' and 'Game', both of them resizable. To make all images scale, I use in the beginning in the main file:
window = pygame.display.set_mode(reso,pygame.RESIZABLE)
window_fake = window.copy()
and inside the loops of the two screens I blit all images on the fake window and blit that to scale on the display window:
window.blit(pygame.transform.scale(window_fake, reso_act),(0,0))
pygame.display.flip()
for event in pygame.event.get():
if event.type==pygame.VIDEORESIZE:
reso_act = event.dict['size']
Now all images scale along when resizing the display. However, when I go from 'Menu' to 'Game' after resizing it, I need the size of the actual display to use as my variable reso_act
, because I again blit everything onto my fake window and scale that to the display window, however there is no VIDEORESIZE
event.
So now if I make the display smaller in 'Menu', then click start and draw 'Game', it will have the original resolution and half of the images are outside of the display.
I have tried the following, but they all give me the value of reso
, the original unresized resolution:
window.get_size()
window_fake.get_size()
pygame.display.get_surface().get_size()
window.get_rect()
window_fake.get_rect()
Is there a way to get the real size of the display? Or otherwise a smarter way to achieve what I want to do?
Upvotes: 1
Views: 105
Reputation: 31
I now solved it by returning reso_act
every time from all the functions for the different screens and also passing it as input for all those functions, so it remembers the setting.
It is not so elegant, but it works.
If someone knows how to get the actual size of the display I would still be interested to know though.
Upvotes: 1