Ive had a problem with surface transparency in pygame, and its making me frustrated. I tried to find solutions from other posts, other sites, but to no avail. The problem is that when i try to make the surface transparent or translucent, it only returns the same surface but darker, even though i put SRCALPHA in the arguments.
Code:
import pygame
from pygame import Color
class Box:
def __init__(self,
surface:pygame.Surface,
pos:tuple[int, int],
size:tuple[int, int],
borderwidth:int,
bg: tuple[int, int, int] | Color | str,
bc: tuple[int, int, int] | Color | str):
self.surface = surface
self.abspos = tuple([x+y for x, y in zip(self.surface.get_rect().topleft, pos)])
self.bw = borderwidth
self.body = pygame.Surface(size, pygame.SRCALPHA, 32)
self.border_body = pygame.Surface([x+self.bw for x in size], pygame.SRCALPHA, 32)
self.rect = pygame.Rect(pos, size)
self.bg = bg
self.bc = bc
def _draw(self):
self.body.fill(self.bg)
self.border_body.fill(self.bc)
def _place(self):
self.surface.blit(self.border_body, [x-self.bw//2 for x in self.rect.topleft])
self.surface.blit(self.body, self.rect.topleft)
def place(self):
self._draw()
self._place()