Ok, so I have been using a special_flags BLEND_MULT surface to add some lighting to a little game I am making in pygame.
The works fine when the program is windowed however, whenever I try to make the Window Fullscreen the BLEND surface does not fullscreen with the rest of the components, it just extends off the edge of the screen. Therefore any gradients blitted to the BLEND surface are also in the wrong position.
This image shows the error when I have the Window Full screened
I know this is an issue with the special_flags (and not me blitting the surface incorrectly) because when I remove the special_flags parameter the surface Fills screens perfectly with the rest of the components
This image shows the window correctly Full screening
Basically I am asking for a way to fix this bug so that I can keep the special_flags parameter without it breaking on Full screen. this way I don't have to completely redo my lighting.
Here is the code which draws surface (fog surface) to the game display
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)
Here is an example that shows the same error when going fullscreen, just simply press f to do so
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()