Reputation: 1336
Everything is working fine except that font thing, i don't know why it's happening and it's not even showing any error. And not displaying the Text on screen.
# import library here
import pygame
import time
import sys
# display init
display_width = 800
display_height = 600
# game initialization done
pygame.init()
# game display changed
gameDisplay = pygame.display.set_mode((display_width, display_height))
# init font object with font size 25
font = pygame.font.SysFont(None, 25)
def message_to_display(msg, color):
screen_text = font.render(msg, True, color)
gameDisplay.blit(screen_text, [10, 10])
message_to_display("You Lose", red)
time.sleep(3)
pygame.quit()
# you can signoff now, everything looks good!
quit()
Upvotes: 0
Views: 3061
Reputation: 9736
The reason you see nothing is because you haven't updated or 'flipped' the display. After you've created the text Surface and blit it to the gameDisplay Surface you have to update/'flip' the display so it becomes visible to the user.
So, between message_to_display("You Lose", red)
and time.sleep(3)
you put pygame.display.update()
or pygame.display.flip()
(it doesn't matter which). Like this:
# import library here
import pygame
import time
import sys
# display init
display_width = 800
display_height = 600
# game initialization done
pygame.init()
# game display changed
gameDisplay = pygame.display.set_mode((display_width, display_height))
# init font object with font size 25
font = pygame.font.SysFont(None, 25)
def message_to_display(msg, color):
screen_text = font.render(msg, True, color)
gameDisplay.blit(screen_text, [10, 10])
message_to_display("You Lose", red)
pygame.display.update() # VERY IMPORTANT! THIS IS WHAT YOU MISSED!
time.sleep(3)
pygame.quit()
# you can signoff now, everything looks good!
quit()
Also, as J.J. Hakala pointed out, you have to define red in message_to_display("You Lose", red)
as well.
Upvotes: 2