Python 屏幕大小调整游戏
我试图从菜单中调整我的游戏大小,但我被卡住了。当我点击新游戏时,我正在尝试缩放屏幕的大小,菜单必须是。既然我找不到其他东西,有没有人知道如何解决这个问题Python 屏幕大小调整游戏,python,pygame,Python,Pygame,我试图从菜单中调整我的游戏大小,但我被卡住了。当我点击新游戏时,我正在尝试缩放屏幕的大小,菜单必须是。既然我找不到其他东西,有没有人知道如何解决这个问题 import pygame import runpy import webbrowser, os from Game import * pygame.init() class Option: hovered = False def __init__(self, text, pos): self.text
import pygame
import runpy
import webbrowser, os
from Game import *
pygame.init()
class Option:
hovered = False
def __init__(self, text, pos):
self.text = text
self.pos = pos
self.set_rect()
self.draw()
def draw(self):
self.set_rend()
screen.blit(self.rend, self.rect,)
def set_rend(self):
self.rend = menu_font.render(self.text, True, self.get_color())
def get_color(self):
if self.hovered:
return (255,255,255)
else:
return (100,100,100)
def set_rect(self):
self.set_rend()
self.rect = self.rend.get_rect()
self.rect.topleft = self.pos
def onSelect(self):
if self.text == "Quit":
pygame.quit()
quit()
if self.text == "Instructions":
webbrowser.open_new("file://" + os.path.realpath("Manual.pdf"))
**if self.text == "New game":
Main()**
class Background(pygame.sprite.Sprite):
def __init__(self, image_file,):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(image_file)
self.rect = self.image.get_rect()
pygame.init()
pygame.mixer.music.load('Really Slow Motion - Fjord Keeper (Epic Intense Uplifting).mp3')
pygame.mixer.music.play(-1)
BackGround = Background('bg.png')
screen = pygame.display.set_mode((480, 320))
menu_font = pygame.font.Font(None, 40)
options = [Option("New game", (2, 195)), Option("Instructions", (2, 245)),
Option("Quit", (2, 295))]
while True:
pygame.event.pump()
screen.fill((0, 0, 0))
screen.blit(BackGround.image, BackGround.rect)
ev = pygame.event.get()
for event in ev:
if event.type == pygame.QUIT:
pygame.quit()
for option in options:
if option.rect.collidepoint(pygame.mouse.get_pos()):
option.hovered = True
else:
option.hovered = False
if option.hovered:
for event in ev:
if event.type == pygame.MOUSEBUTTONDOWN:
option.onSelect()
option.draw()
pygame.display.update()
到目前为止,这是我的菜单,但我正在尝试将其缩放为1300x1000。我在手机上,不知道如何编写代码,所以我只需键入它,k?K screen=pygame.display.set_模式((13001300)) 把这个放在你想换的地方。假设你把它作为f键。然后,当您按f键时,它应将屏幕分辨率更改为set_模式