好的,所以我一直在使用special_flags BLEND_MULT表面为我在pygame中制作的小游戏添加一些光照。
当程序窗口化时工作正常但是,每当我尝试使窗口全屏幕的BLEND表面不与其余组件全屏时,它只是延伸到屏幕边缘。因此,BLEND表面上的任何渐变都处于错误的位置。
This image shows the error when I have the Window Full screened
我知道这是special_flags的一个问题(而不是我错误地将表面弄错)因为当我删除了special_flags参数时,表面填充屏幕与其他组件完美匹配
This image shows the window correctly Full screening
基本上我要求一种方法来修复这个bug,以便我可以保留special_flags参数,而不会在全屏幕上打破。这样我就不必完全重做我的照明。
以下是将表面(雾面)绘制到游戏显示中的代码
def render_fog(self):
#draw light onto fog
for fog in self.all_fog:
fog.image.fill(fog.colour)
self.light_rect.centerx = self.player.rect.centerx - fog.x
self.light_rect.centery = self.player.rect.centery - fog.y
fog.image.blit(self.light_mask, self.light_rect)
for light in self.all_light:
light.centerx = light.x
light.centery = light.y
fog.image.blit(light.image, (light.rect))
self.gameDisplay.blit(fog.image, (fog.x, fog.y), special_flags = pygame.BLEND_MULT)
这是一个在全屏显示相同错误的示例,只需按f即可
import pygame
import sys
from os import path
from time import sleep
import random
WIDTH = 864
HEIGHT = 512
NIGHT_COLOR = (20, 20, 20)
RED = (255, 0, 0)
class Game:
def __init__(self):
pygame.init()
self.gameDisplay = pygame.display.set_mode((WIDTH, HEIGHT))
self.clock = pygame.time.Clock()
self.running = True
self.fullscreen = False
self.load_data()
def load_data(self):
self.fog = pygame.Surface((WIDTH, HEIGHT))
self.fog.fill(NIGHT_COLOR)
def quit(self):
pygame.quit()
sys.exit()
def run(self):
self.playing = True
while self.playing:
self.dt = self.clock.tick(60) / 1000
self.events()
self.draw()
def events(self):
for e in pygame.event.get():
if e.type == pygame.QUIT:
self.quit()
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_f:
self.fullscreen = not self.fullscreen
def render_fog(self):
self.fog.fill(NIGHT_COLOR)
self.gameDisplay.blit(self.fog, (0, 0), special_flags =
pygame.BLEND_MULT)
def draw(self):
pygame.display.set_caption("FPS:
{:.2f}".format(self.clock.get_fps()))
if self.fullscreen:
self.gameDisplay = pygame.display.set_mode((864, 512),
pygame.FULLSCREEN)
else:
self.gameDisplay = pygame.display.set_mode((864, 512))
self.gameDisplay.fill(RED)
self.render_fog()
pygame.display.update()
g = Game()
while g.running:
g.run()