Python Forum
Testing resolution for pygame window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Testing resolution for pygame window
#1
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)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply
#2
Very good game.
Reply
#3
What is the purpose of this exercise?
Reply
#4
@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.
likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Cannot display anything inside pygame window the_gullwing 5 3,374 Dec-07-2023, 02:44 AM
Last Post: Benixon
  [PyGame] drawing images onto pygame window djwilson0495 1 4,572 Feb-22-2021, 05:39 PM
Last Post: nilamo
  pygame get window position vskarica 3 8,260 Oct-18-2020, 05:14 PM
Last Post: nilamo
  Unable to exit Pygame window Hesper 2 5,215 Mar-30-2020, 08:59 AM
Last Post: Hesper
  [pyGame] More Text in one Window, example needed ! JamieVanCadsand 1 4,354 Oct-03-2017, 03:42 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020