2016-06-29 8 views
0

フォント以外のものはすべてうまく動作していますが、なぜそれが起こっているのか分かりませんし、エラーも表示されません。テキストを画面に表示しない。あなたがいないまたはを更新表示 'をひっくり返し' しているので、あなたが何も見えないpygame.fontは動作しておらず、エラーも表示されていません

# 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() 
+1

'message_to_display(" You Lose "、red)の' red'はどこにも定義されていません –

答えて

2

理由があります。テキストSurfaceを作成してそれをgameDisplay Surfaceにblitした後は、ユーザーが見ることができるようにディスプレイを更新/ '反転'する必要があります。

だから、message_to_display("You Lose", red)time.sleep(3)の間、あなたは入れpygame.display.update()またはpygame.display.flip()(それがどの問題ではありません)。このように:

# 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() 

また、として.J。 Hakalaが指摘された場合、message_to_display("You Lose", red)にも定義する必要があります。

関連する問題