screen.fill似乎不起作用

时间:2017-07-23 08:29:16

标签: python

我很喜欢编程游戏,一切正常,所以现在我想要的是游戏开始之前的屏幕。然后,您必须单击开始才能继续游戏。到目前为止,我有这段代码:

if menu == 'start':
    screen.fill((0,255,0))
    txt = font.render('Start',True,(255,255,0))
    txt_x = 480
    txt_y = 290
    buttonrect = pygame.Rect((txt_x,txt_y),txt.get_size())
    pygame.draw.rect(screen,(0,0,255),buttonrect)
    screen.blit(txt,(txt_x,txt_y))
    if pygame.mouse.get_pressed()[0] and buttonrect.collidepoint(pygame.mouse.get_pos()):
        menu = 'game'

我已将菜单设置为“开始”但不起作用。屏幕是黑色而不是绿色。但是当我点击坐标时,我会去游戏。我的代码出了什么问题?

1 个答案:

答案 0 :(得分:0)

您需要在设置屏幕背景后更新主显示屏:

if menu == 'start':
    screen.fill((0,255,0))
    txt = font.render('Start',True,(255,255,0))
    txt_x = 480
    txt_y = 290
    buttonrect = pygame.Rect((txt_x,txt_y),txt.get_size())
    pygame.draw.rect(screen,(0,0,255),buttonrect)
    screen.blit(txt,(txt_x,txt_y))

    pygame.display.update()

    if pygame.mouse.get_pressed()[0] and buttonrect.collidepoint(pygame.mouse.get_pos()):
        menu = 'game'