Item Fehler gefixt

This commit is contained in:
Benjamin 2026-10-16 17:24:28 +02:00
parent b0b979d80b
commit f41f872243
2 changed files with 35 additions and 1 deletions

View file

@ -26,8 +26,8 @@ class Item:
self.visible: bool = False self.visible: bool = False
self.flashlight = flashlight self.flashlight = flashlight
self.game = game self.game = game
self.mask = pygame.mask.Mask(self.rect.size, fill=True)
self.image = image self.image = image
self.mask = pygame.mask.Mask(self.rect.size, fill=True)
@property @property
def rect(self) -> pygame.Rect: def rect(self) -> pygame.Rect:

34
testen/masken.py Normal file
View file

@ -0,0 +1,34 @@
import pygame
pygame.init()
screen = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()
running = True
image = pygame.Surface((200, 200), pygame.SRCALPHA)
image.fill("blue")
pygame.draw.rect(image, "red", (0, 100, 200, 100))
selection = pygame.Surface((200, 200), pygame.SRCALPHA)
pygame.draw.circle(selection, "white", (100, 100), 80)
mask = pygame.mask.from_surface(selection)
mask_view = mask.to_surface()
result = mask.to_surface(setsurface=image, unsetcolor=(0, 0, 0, 0))
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill("grey")
screen.blit(image, (260, 260))
screen.blit(mask_view, (540, 260))
screen.blit(result, (820, 260))
pygame.display.flip()
clock.tick(60)
pygame.quit()