2017-05-31 8 views
2

このコードを実行すると、 "ValueError:size(int width、int height)にする必要があります"というエラーが表示されます。私は値800と600、同じエラーのために変数を代入しようとしたpygameの画面にテキストを追加する際に問題が発生しました

pygame.Surface.blit(pygame.Surface(display_width, display_height), welcomeMessageBackground, area = None, special_flags = 0) 

display_width = 800 
display_height = 600 
welcomeScreen = pygame.display.set_mode((display_width, display_height)) 

red = (255, 0, 0) 
white = (255, 255, 255) 

welcomeScreen.fill(white, rect = None, special_flags = 0) 

welcomeMessageBackground = pygame.draw.rect(welcomeScreen, red, [200, 100, 400, 75]) 
welcomeFont = pygame.font.Font(None, 50) 
welcomeMessage = welcomeFont.render('Welcome! Click a button to get started.', True, white) 
pygame.Surface.blit(pygame.Surface(display_width, display_height), welcomeMessageBackground, area = None, special_flags = 0) 
pygame.display.update() 

問題を引き起こす行があります。私が欲しいのは、welcomeMessageのテキストが矩形welcomeMessageBackground上に表示されることです。どんな助けもありがとう!

答えて

0

あなたは価値のためtupleを使用する必要があります。

pygame.Surface.blit(pygame.Surface((display_width, display_height)), welcomeMessageBackground, area = None, special_flags = 0) 

だから動作するはず()中にあなたdisplay_widthdisplay_heightを包みます。 documentationを確認してください。

1

この行は意味がありません。

pygame.Surface.blit(pygame.Surface(display_width, display_height), welcomeMessageBackground, area = None, special_flags = 0) 

あなたは例えば、pygame.Surface.blit()いますが、他の面をブリットしたい、その上に表面のブリットメソッドを呼び出すべきではありません。

welcomeScreen.blit(welcomeMessage, (70, 100)) 

welcomeFont.renderは、画面上にブリットすることができ、表面を返します。または別の表面を有する。


pygame.Surfaceインスタンスを作成するには、幅と高さ、 pygame.Surface((100, 200))のためのタプルを渡す必要がありますが、あなたのケースでは、あなたは全く別の表面を作成する必要はありません。また


、テキストの背景色を追加したい場合、あなたは自分のフォントのrender方法に色を渡すことができます。

welcomeMessage = welcomeFont.render(
    'Welcome! Click a button to get started.', True, white, red) 
関連する問題