简体   繁体   中英

How to choose a set window size while in fullscreen, pygame

I updated to pygame 2.1.3.dev8 (Which is the latest supported version for my raspi) because I needed a feature from 2.1.3, and this changed how fullscreen works. I want to create a game with a lower resolution, to mimic older consoles and games.

The system I have in place uses a "scale" variable I have set to 3, and I use this everywhere I would choose the size and position for something.

variable.py:

import pygame
width = 256
height = 224
scale = 3
background = pygame.image.load("images/background.png") #Just colour
clock = pygame.time.Clock()

screen = pygame.display.set_mode((width*scale, height*scale), pygame.FULLSCREEN)

FPSlock = 60

colour = (155, 0, 0)

outerLayer.py:

from variable import *
from slimeGame import *


def mainScreenUpdate():
    screen.fill(colour)
    pygame.display.update()

run = True

while run:
    clock.tick(FPSlock)
    mainScreenUpdate()
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                run = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RETURN:
                slimeGameFunction()

slimeGame.py:

from variable import *

def screenUpdate():
    screen.blit(pygame.transform.scale(background, (width*scale, height*scale)), (0, 0))
    pygame.display.update()

def slimeGameFunction():
    slimeGameRun = True
    while slimeGameRun:
        clock.tick(FPSlock)
        screenUpdate()
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    slimeGameRun = False

I expected the fullscreened window to be the same as the given size, with black borders at the edges, but what happened was that it fit to the screen's resolution despite the specified size.

(The outerLayer.py file is the one that needs to be started)

Try setting pygame.RESIZABLE flag in addition to the pygame.FULLSCREEN flag.

screen = pygame.display.set_mode((width*scale, height*scale), pygame.FULLSCREEN | pygame.RESIZABLE)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM