i wondering how go scaling size of images in pygame projects resolution of screen. example, envisage following scenario assuming windowed display mode time being; assume full screen same:
i have
1600x900background image of course displays natively in1600x900windowin
1280x720window can scale images' rect1280x720what happens, if need add,
300x300 pximage @x,y 1440,860(example sizes) sized fit original1600x900background? of course1600x900can of course use image natively smaller/larger window sizes?
basically, how scale images window size , position them accordingly? guess there must easy automated method right can't figure out , quite frankly haven't got time search it...
thanks in advance, ilmiont
you can scale image pygame.transform.scale:
import pygame picture = pygame.image.load(filename) picture = pygame.transform.scale(picture, (1280, 720)) you can bounding rectangle of picture with
rect = picture.get_rect() and move picture with
rect = rect.move((x, y)) screen.blit(picture, rect) where screen set like
screen = pygame.display.set_mode((1600, 900)) to allow widgets adjust various screen sizes, make display resizable:
import os import pygame pygame.locals import * pygame.init() screen = pygame.display.set_mode((500, 500), hwsurface | doublebuf | resizable) pic = pygame.image.load("image.png") screen.blit(pygame.transform.scale(pic, (500, 500)), (0, 0)) pygame.display.flip() while true: pygame.event.pump() event = pygame.event.wait() if event.type == quit: pygame.display.quit() elif event.type == videoresize: screen = pygame.display.set_mode( event.dict['size'], hwsurface | doublebuf | resizable) screen.blit(pygame.transform.scale(pic, event.dict['size']), (0, 0)) pygame.display.flip()