I was wondering how I would go about scaling the size of images in pygame
projects to the resolution of the screen. For example, envisage the following scenario assuming windowed display mode for the time being; I assume full screen will be the same:
I have a
1600x900
background image which of course displays natively in a1600x900
windowIn a
1280x720
window I can obviously just scale this images' rect to1280x720
What happens, however if I need to add, say a
300x300 px
image atx,y 1440,860
(example sizes) that is sized to fit with the original1600x900
background? Of course for the1600x900
I can of course use the image natively but what about the smaller/larger window sizes?
Basically, how do I scale images to the window size and then position them accordingly? I guess there must be a REALLY easy automated method but right now I can't figure it out and quite frankly haven't got time to search for it...
Thanks in advance, Ilmiont
You can scale the image with
pygame.transform.scale
:You can then get the bounding rectangle of
picture
withand move the picture with
where
screen
was set with something likeTo allow your widgets to adjust to various screen sizes, you could make the display resizable:
If you scale 1600x900 to 1280x720 you have
Than you can use it to find button size, and button position
If you scale 1280x720 to 1600x900 you have
and rest is the same.
I add
.0
to value to makefloat
- otherwisescale_x
,scale_y
will be rounded tointeger
- in this example to0
(zero) (Python 2.x)