I am coding a game in which the player enters its name, and I'd like to blit it on the screen.
Heres how I take the name (name is a string that is put in global in the following function):
while player_name_screen:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
print(name)
menu_screen = False
player_name_screen = False
game_animation = True
enemy_animation = True
standing = True
else:
name += event.unicode
name_text = game_font.render(name, True, (125, 156, 255))
win.blit(name_text, (500, 500))
pygame.display.update()
clock.tick(fps)
And here's how I wanna blit player's name (following code is in a fonction, that is called in my main loop):
if game_animation:
win.blit(name_text, (100, 300))
But nothing appears on the screen, and when I print this in the shell, It appears like this : <Surface(63x50x32 SW)>
How can I make it blit correctly on the screen ? I looked already for similar questions but couldn't find one that answers my problem.
Thanks for your help
Edit : Heres the whole thing that is needed for this to work:
name = ""
name_text = game_font.render('', True, (255, 255, 255))
def input_player_name():
global menu_screen
global game_animation
global enemy_animation
global standing
global deluxe_or_not
global name
global name_text
#print("Enter player's name")
player_name_screen = True
win.blit(playerNameImg, (0, 0))
while player_name_screen:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
print(name)
menu_screen = False
player_name_screen = False
game_animation = True
enemy_animation = True
standing = True
imperial_march.play()
if "deluxe.ver" in name:
print("deluxe.ver.exe")
deluxe_or_not = 1
else:
name += event.unicode
#print(name)
name_text = game_font.render(name, True, (125, 156, 255))
win.blit(name_text, (500, 500))
pygame.display.update()
clock.tick(fps)
def rwg():
if game_animation:
win.blit(name_text, (100, 300))
print(name_text)
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and menu_screen == True:
input_player_name()
rwg()