我正在制作全屏游戏,我正在尽力确保它适合所有屏幕尺寸。这证明非常困难,因为当我使用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语句是针对开放的徽标序列。
答案 0 :(得分:0)
首先尝试获得最大的屏幕分辨率。类似的东西:
size = pygame.display.list_modes()[0]
screen = pygame.display.set_mode(size,pg.FULLSCREEN)