Implemented centre()

This commit is contained in:
2025-06-21 23:03:38 +01:00
parent d897a3744d
commit 95afab5431

View File

@ -1,14 +1,22 @@
import pygame
def centre(surface: pygame.Surface, rect: tuple[int, int, int, int]) -> pygame.Surface:
def centre(surface: pygame.Surface, size: tuple[int, int]) -> pygame.Surface:
"""
Centres a surface within a given rectangle.
Args:
surface: The surface to be centred.
rect: The rectangle the surface will be centred in.
size: The size of the rectangle the surface will be centred in.
Returns:
pygame.Surface
"""
pass
surf = pygame.Surface(size)
offX = surf.size[0]//2 - surface.size[0]//2
offY = surf.size[1]//2 - surface.size[1]//2
surf.blit(surface, (offX, offY))
return surf