so making game in python , pygame , have indow setup this
display = pygame.display.set_mode((0,0), pygame.fullscreen)
which makes size of window 1334 x 800 based sprites , backgrounds on size of screen know not has same sized screen me question how can make images scale how big monitor screen is
(p.s game in fullscreen mode)
first, how resolution , scaling factor?
this tricky, because someone's screen may not have same aspect ratio 1334x800. can letterbox (in various different ways) or stretch sprites; need decide want, i'll show 1 letterboxing possibility:
nominal_width, nominal_height = 1334., 800. surface = display.get_surface() width, height = surface.get_width(), surface.get_height() xscale = width / nominal_width yscale = height / nominal_height if xscale < 1 , yscale < 1: scale = max(xscale, yscale) elif xscale > 1 , yscale > 1: scale = min(xscale, yscale) else: scale = 1.0
now, how scale each sprite , background?
well, first, sure want to? may simpler transform whole surface. whether slower or faster hard predict without testing (and not relevant anyway), better (because interpolation, dithering, antialiasing, etc. happens after compositing, instead of before—unless you're going 8-bit look, of course, in case destroy look…). can compositing off-screen surface of 1334x800 (or, better, scaling constant factor), transform
ing surface display. (note transform
methods include optional destsurface
argument. can use directly transform offscreen surface display's surface.)
but let's assume want way asked.
you can when loading sprites. example:
def rescale(surf, scale): new_width, new_height = surf.get_width() * scale, surf.get_height() * scale return pygame.transform.smoothscale(surf, (new_width, new_height)) class scaledsprite(pygame.sprite.sprite): def __init__(self, path, scale): pygame.sprite.sprite.__init__(self) self.image = rescale(pygame.image.load(path), scale) self.rect = self.image.get_rect()
and same backgrounds.