I’m trying to create a pygame function that will alter the size/coordinates of sprites/object images by a proportional amount to the change in screen size.
So far I have the following but it doesn’t change the size of images at all (no errors returned either):
def update_screen_scaling(event,all_sprites):
if event.type == VIDEORESIZE:
current_display = pg.display.get_surface().get_size()
screen = pg.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE)
for item in all_sprites:
item.image = pg.transform.scale_by(item.image, (event.dict['w']/current_display[0],event.dict['h']/current_display[1]))
item.selfrect = item.image.get_rect(topleft=((event.dict['w']/current_display[0])*item.selfrect.left,(event.dict['h']/current_display[1])*item.selfrect.top))
screen.blit(item.image,item.selfrect)
pg.display.flip()
image and selfrect are just attributes for the object’s image and rect respectively.