Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pygame Display Width

I am using full screen for pygame, however I want to set some boundaries so that my player cannot escape the screen. I originally set boundaries like this:

if x > display_width - player_width or x < 0
    crash()

However, this will not work since there is not fixed display_width, is there some way that I can get a display width? Or can I use some other method to set boundaries on the screen.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I believe this is what your looking for. It will provide the width and height, as a tuple.

width, height = pygame.display.get_surface().get_size()

Credit: How do I get the size (width x height) of my pygame window

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading