Я понял это с помощью ответа Кингсли.Теперь вы можете добавить тень или нет, где она расположена и какого она цвета.Может быть, есть более простой способ, но у меня это получилось.
import pygame
import sys
pygame.init()
screenSizeX = 1080
screenSizeY = 720
screenSize = (screenSizeX,screenSizeY)
screen = pygame.display.set_mode(screenSize,0)
pygame.display.set_caption("Test Functions")
WHITE = (255,255,255)
GREEN = (0,255,0)
BLUE = (0,0,255)
RED = (255,0,0)
YELLOW = (255,255,0)
BLACK = (0,0,0)
MAGENTA = (139,0,139)
def horCenter(font, size, text, colour, yPos, shadow, shadowPlace, shadowColour):
fontTitle = pygame.font.SysFont(font, size)
textTitle = fontTitle.render(text, True, colour)
textWidth = textTitle.get_width()
xPos = screenSizeX/2 - textWidth/2
if shadow == "True":
dropShadow(font,size,text,colour, xPos,yPos, shadowPlace, shadowColour)
else:
screen.blit(textTitle, (xPos, yPos))
def verCenter(font, size, text, colour, xPos, shadow, shadowPlace, shadowColour):
fontTitle = pygame.font.SysFont(font, size)
textTitle = fontTitle.render(text, True, colour)
textHeight = textTitle.get_height()
yPos = screenSizeY/2 - textHeight/2
if shadow == "True":
dropShadow(font,size,text,colour, xPos,yPos, shadowPlace, shadowColour)
else:
screen.blit(textTitle, (xPos, yPos))
def cenCenter(font, size, text, colour, shadow, shadowPlace, shadowColour):
fontTitle = pygame.font.SysFont(font, size)
textTitle = fontTitle.render(text, True, colour)
textHeight = textTitle.get_height()
textWidth = textTitle.get_width()
xPos = screenSizeX/2 - textWidth/2
yPos = screenSizeY/2 - textHeight/2
if shadow == "True":
dropShadow(font,size,text,colour, xPos,yPos, shadowPlace, shadowColour)
else:
screen.blit(textTitle, (xPos, yPos))
def dropShadow(font, size, text, colour, xPos,yPos, shadowPlace, shadowColour):
fontTitle = pygame.font.SysFont(font, size)
textTitle = fontTitle.render(text, True, colour)
shadowTitle = fontTitle.render(text, True, shadowColour)
if shadowPlace == "bottomRight":
newXPos = xPos +2
newYPos = yPos + 2
screen.blit(shadowTitle, (newXPos,newYPos))
screen.blit(textTitle, (xPos,yPos))
elif shadowPlace == "bottomLeft":
newXPos = xPos - 2
newYPos = yPos + 2
screen.blit(shadowTitle, (newXPos, newYPos))
screen.blit(textTitle, (xPos, yPos))
elif shadowPlace == "topRight":
newXPos = xPos - 2
newYPos = yPos - 2
screen.blit(shadowTitle, (newXPos, newYPos))
screen.blit(textTitle, (xPos, yPos))
elif shadowPlace == "topLeft":
newXPos = xPos + 2
newYPos = yPos - 2
screen.blit(shadowTitle, (newXPos, newYPos))
screen.blit(textTitle, (xPos, yPos))
pygame.display.update()
go = True
while go:
for event in pygame.event.get():
if event.type ==pygame.QUIT:
go = False
screen.fill(WHITE)
horCenter("Comic Sans MS", 40, "Thanos", MAGENTA, 100, "True", "topLeft", YELLOW)
verCenter("Georgia", 10, "HULK SMASH", GREEN, 800, "True", "bottomRight", BLACK)
cenCenter("Impact", 50, "MARVEL", RED, "True", "bottomRight", BLACK)
verCenter("Verdana", 60, "Black Widow", BLACK, 50, "True", "topRight", RED)
pygame.display.update()
pygame.quit()
sys.exit()