gpt4 book ai didi

python - pygame.FULLSCREEN 太大

转载 作者:行者123 更新时间:2023-12-02 04:45:32 25 4
gpt4 key购买 nike

我正在开发一款全屏游戏,我正在尽最大努力确保它适合所有屏幕尺寸。这被证明是相当困难的,因为当我使用 pygame.FULLSCREEN 时,窗口比屏幕大得多。为了解决这个问题,我根据 python 将屏幕尺寸设为我的屏幕尺寸的 83%。在我的电脑上看起来还不错,但现在如果我在其他电脑和屏幕上使用相同的代码,屏幕就太小了。这是代码:

infoObject = pygame.display.Info()
print(infoObject)
w = int(infoObject.current_w*0.83)
h = int(infoObject.current_h*0.83)
gameDisplay = pygame.display.set_mode((w, h), pygame.FULLSCREEN)

这会创建一个几乎完全适合屏幕的窗口,但我不知道为什么全屏不能自行工作...请帮忙!

完整代码:

import pygame, time

pygame.init()

white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
green = (0,155,0)
blue = (0,0,255)

def button(x,y,w,h,action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if x+w > mouse[0] > x and y+h > mouse[1] > y:
if click [0] == 1 and action != None:
if action == "exit":
pygame.quit()
quit()
infoObject = pygame.display.Info()
print(infoObject)
w = int(infoObject.current_w*0.83)
h = int(infoObject.current_h*0.83)
size = pygame.display.list_modes()[0]
gameDisplay = pygame.display.set_mode(size,pygame.FULLSCREEN)
pygame.display.set_caption("Turf War")
clock = pygame.time.Clock()

gameExit = False
gameExit = False

box1X = 384
box1Y = 810
box2X = 1526
box2Y = 810
box3X = 384
box3Y = 260
box4X = 1526
box4Y = 260

box1 = pygame.Surface(((int(round(box1X*0.83))),(int(round(box1Y*0.83)))))
box1.set_alpha(220)
box1.fill((0,0,0))

box2 = pygame.Surface((((int(round(box2X*0.83)))-20(int(round(box2Y*0.83)))))
box2.set_alpha(220)
box2.fill((0,0,0))

box3 = pygame.Surface(((int(round(box3X*0.83))),((int(round(box3Y*0.83)))-20)))
box3.set_alpha(220)
box3.fill((0,0,0))

box4 = pygame.Surface((((int(round(box4X*0.83)))-20),((int(round(box4Y*0.83)))-20)))
box4.set_alpha(220)
box4.fill((0,0,0))

logo1 = pygame.image.load('logo.png')
logo2 = pygame.image.load('logo2.png')
bg = pygame.image.load("bg.png")

start_time = pygame.time.get_ticks() / 1000

while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True

time = pygame.time.get_ticks() / 1000
elapsed = time - start_time

gameDisplay.fill(black)

if elapsed > 4:
gameDisplay.blit(bg,(0,0))
button(0, 0, 10, 10, 'exit')
pygame.draw.rect(gameDisplay, red, (0, 0, 10, 10))
gameDisplay.blit(box1, (10,10))
gameDisplay.blit(box2, ((int(round(box1X*0.83)+20),10)))
gameDisplay.blit(box3, (10,(h-(int(round(box3Y*0.83)))+10)))
gameDisplay.blit(box4, ((int(round(box1X*0.83)+20),(h-(int(round(box3Y*0.83)))+10))))
elif elapsed > 2:
gameDisplay.blit(logo2, ((w*0.22), (h*0.4)))
elif elapsed > 0:
gameDisplay.blit(logo1, ((w*0.22), (h*0.3)))

pygame.display.update()
clock.tick(15)

pygame.quit()
quit()

如果您想知道,主循环中的 if 语句用于打开 Logo 序列。

最佳答案

首先尝试获得最大的屏幕分辨率。像这样的东西:

size = pygame.display.list_modes()[0]
screen = pygame.display.set_mode(size,pg.FULLSCREEN)

关于python - pygame.FULLSCREEN 太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33402361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com