pygame center text in rect 1

pygame center text in rect

# draw text
font = pygame.font.Font(None, 25)
text = font.render("You win!", True, BLACK)
text_rect = text.get_rect(center=(SCREEN_WIDTH/2, SCREEN_HEIGHT/2))
screen.blit(text, text_rect)

Here is what the above code is Doing:
1. Create a font object.
2. Create a text object using the font object.
3. Create a rectangle object for the text.
4. Draw the text to the screen.

Similar Posts