Skip to content
Advertisement

center images and add padding according to screen resolution

I’m using pygame to show two images: I’ve maneged to resize the images according to the screen size of my user. But I’d like to standardized also the x and the y coordination position of my images. The images should always be in the middle according to the y axis and have the a little bit of pad to stay close to the border of the monitor like this no matter what resolution my user has:

enter image description here

This are the values that I’d like to standardized

JavaScript

This is my code right now:

JavaScript

Advertisement

Answer

Get the bounding rectangle of the image and set the centery and left or right of the rectangle depending on the size of WIN. Use the rectangles to blit the images:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement