2017-08-23 38 views
0

我剛開始使用PyGame,我試圖讓消息顯示玩家輸了,但是我收到錯誤。PyGame錯誤:RGBA參數

red = (2555, 0, 0) 
font = pygame.font.SysFont(None, 25) 

def message_to_screen(msg,color): 
    screen_text = font.render(msg, True, color) 
    gameDisplay.blit(screen_text, [display_width/2, display_height/2]) 

--etc等

message_to_screen("You Lose", red) 
pygame.display.update() 

time.sleep(2) 

確切的錯誤信息是

screen_text = font.render(msg, True, color) 
TypeError: Invalid foreground RGBA argument 

我不能找到任何答案。請幫忙!

+1

每個通道的範圍爲0到255. 2555太大。 – Arkia

回答

0

您的問題是與你的顏色定義:

red = (2555, 0, 0) 

每個RGB信道的可能值可以在0〜256(不包括)的範圍內。這意味着2555是waaay要大。 Pygame看到這一點,並正確地提出了一個錯誤。如果你想編碼紅色的RGB值,你需要使用255不是2555:

red = (255, 0, 0) 

作爲一個側面說明,你可能會發現類似的RGB color selector是有幫助的,而在過程爲你的遊戲選擇顏色。