【发布时间】:2022-01-21 02:12:53
【问题描述】:
因此,我一直在尝试创建一个小代码,该代码将使用 pygame.RESIZABLE 在我的屏幕上缩放图像,以便能够根据需要调整我的游戏窗口大小,而不会破坏代码中的任何垫子。我发现解决这个问题的方法是在 pygame.Surface 上对我的游戏中的所有内容进行 blitting,然后我会缩放以适合我的 pygame.display 一切正常,但是当我使用 game.fill('black') 时它不会' t 似乎填满了我的屏幕,我在屏幕上绘制的用于测试缩放的正方形没有移动。我知道这是导致问题的 game.fill('black') 行,因为如果我删除该行,正方形会自行缩放,但屏幕不会刷新。请帮忙。
# Setup
import pygame
from sys import exit
pygame.init()
# Settings
tile_size = 64
game_width = 1200
game_height = 700
screen_width = game_width
screen_height = game_height
screen = pygame.display.set_mode((screen_width,screen_height),pygame.RESIZABLE)
game = pygame.Surface((game_width,game_height))
pygame.display.set_caption('Image resize')
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.VIDEORESIZE:
screen_width = screen.get_height() * screen_width / screen_height
screen_height = screen.get_height()
game = pygame.transform.scale(game,(screen_width,screen_height))
screen.fill('black')
game.fill('black') # This is the line that I think isn't working try commenting it out to see that the rest of the code is working fine just not refreshing which is the purpose of this line
pygame.draw.rect(game,'red',(tile_size,tile_size,tile_size,tile_size))
screen.blit(game,(0,0))
pygame.display.update()
clock.tick(60)
【问题讨论】:
-
当然可以。
gameSurface 上有 2 个方格。调整大小之前的那个,以及在应用程序循环中不断绘制的那个。 -
是的,我如何删除第一个
标签: python pygame fill surface