Python Forum

Full Version: Testing resolution for pygame window
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
As the title says. Was just wondering if I could get some feedback on where the cyan square is placed on various screens.
On mine it's where I would expect. If the window is too big for the window close, pressing any key will close the window
I'll post the code and image of my screen

import pygame

pygame.init()



# Screen resolution and color
monitor = pygame.display.Info()
resolution = (monitor.current_w, monitor.current_h/1.1)
screen = pygame.display.set_mode(resolution)
screen_color = '#222222'

# Setup framerate
clock = pygame.time.Clock()
fps = 60

# Set some flags
running = True

player_sprite = pygame.sprite.Group()
allsprites = pygame.sprite.Group()

class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((50,50))
        self.image.fill('cyan')
        self.rect = self.image.get_rect()
        self.rect.x = resolution[0]/2
        self.rect.y = resolution[1] - self.rect.height*1.5

        player_sprite.add(self)
        allsprites.add(self)

# Create the player
player = Player()

while running:
    screen.fill(screen_color)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN:
            running = False

    allsprites.update()
    allsprites.draw(screen)

    pygame.display.update()
    clock.tick(fps)
Very good game.
What is the purpose of this exercise?
@deanhystad
Was just testing resizing of game images based on screen resolution.
I found another way of doing it as the code I provided had errors.