I’m working on a Pygame project for a school assignment and I am having an issue where a line of text isn’t centred correctly on the screen. The function creates two lines of text but one of them is offset from the centre of the screen.
I’m using Python 3.9 and Pygame 2.5.2.
Here is the function that draws the frame:
def deathScreen(variables):
screen.fill(Color(255, 0, 0))
text1 = "You Died!"
titleFont = pygame.font.SysFont("Arial", round(screenWidth * 0.05))
titleText = titleFont.render(text1, False, Color(0, 0, 0))
titleRect = pygame.Rect(0, 0, titleFont.size(text2)[0], titleFont.size(text2)[1])
titleRect.center = Vector2(screenWidth * 0.5, screenHeight * 0.25)
screen.blit(titleText, titleRect)
text2 = "Score: " + str(variables["score"])
scoreFont = pygame.font.SysFont("Arial", round(screenWidth * 0.025))
scoreText = scoreFont.render(text2, False, Color(0, 0, 0))
scoreRect = pygame.Rect(0, 0, scoreFont.size(text2)[0], scoreFont.size(text2)[1])
scoreRect.center = Vector2(screenWidth * 0.5, screenHeight * 0.35)
screen.blit(scoreText, scoreRect)
I’ve tried changing the position of the text but I can’t seem to get it to line up. I also do not understand why every other line is centred correctly except for this one.
user24884394 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.