2017-08-23 40 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是有帮助的,而在过程为你的游戏选择颜色。