Implemented centre()
This commit is contained in:
@ -1,14 +1,22 @@
|
|||||||
import pygame
|
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.
|
Centres a surface within a given rectangle.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
surface: The surface to be centred.
|
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:
|
Returns:
|
||||||
pygame.Surface
|
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
|
||||||
|
|
||||||
Reference in New Issue
Block a user